Hello,
i want to use bind to create a pair and forward it to an std::ostream, i.e. like:
std::for_each(vec.begin(), vec.end(),
bind(&write,
std::cout,
bind(constructor >(), _1, _1)));
but the compiler says:
ios_base.h:781: error: 'ios_base(const ios_base &)' is private
boost/boost/lambda/detail/bind_functions.hpp:472: error: within this context
boost/boost/lambda/detail/function_adaptors.hpp: In static member function
`static void boost::lambda::function_adaptor<
void (*)(ostream &, const pair &)
>::apply(
void (*)(ostream &, const pair &),
const ostream &,
const pair &)'
...
it seem that temporary is created? why? how to avoid it?
i've tried the obvious way (at least for me):
std::for_each(vec.begin(), vec.end(),
(std::cout << bind(constructor >(), _1, _1)));
but now the output from compiler is kind of 'heavy stuff' and i'm having difficulties
to figure out what am i doing wrong.
can you help me, please?
many thanks for your attention,
Mojmir
--------8<---- complete source ------
#include
#include
#include <memory>
#include <vector>
#include <iostream>
using namespace boost::lambda;
typedef int value_t;
typedef std::vector vect_t;
typedef std::vector > vect2_t;
std::ostream & operator<< (std::ostream & os, std::pair const & p)
{ return os; }
void write (std::ostream & os, std::pair const & p) { }
int main ()
{
vect_t vec;
vect2_t vec2;
vec.push_back(1);
std::transform(vec.begin(), vec.end(), std::back_inserter(vec2),
bind(constructor >(), _1, _1)); // ok
/*
std::for_each(vec.begin(), vec.end(),
bind(&write,
std::cout,
bind(constructor >(), _1, _1))
);
std::for_each(vec.begin(), vec.end(),
(std::cout << bind(constructor >(), _1, _1)));
*/
}
This e-mail and any attachment is for authorised use by the intended recipient(s) only. It may contain proprietary material, confidential information and/or be subject to legal privilege. It should not be copied, disclosed to, retained or used by, any other party. If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender. Thank you.