Hi,
I have defined a global overloaded operator<<. I want to use this overloaded operator in std::for_each(), but it must be properly deduced since there are many global overloads for this operator. For example:
class Stream
{
// This is an abstract class (cannot instantiate)
};
Stream& operator<< ( Stream& stream, char data )
{
stream.write( data );
return stream;
}
Stream& operator<< ( Stream& stream, std::vector<char>& buffer )
{
using namespace boost::lambda;
std::for_each( buffer.begin(), buffer.end(), var( stream ) << _1 ); // This lambda should simply be binding to the overloaded operator<< above, right?
return stream;
}
When I compile this, MSVC9 tells me:
1>c:\program files\microsoft visual studio 9.0\vc\include\algorithm(29) : error C2064: term does not evaluate to a function taking 1 arguments
1> class does not define an 'operator()' or a user defined conversion operator to a pointer-to-function or reference-to-function that takes appropriate number of arguments
What am I doing wrong? Do I need to be using boost bind instead? If so, how can I use boost.bind to map a global operator? Will it correctly deduce which overload to use?