boost::lambda library, error with << operator (on g++ with SGI STL)

Hi, I've tried to compile the following code on linux/g++ (version 3.3.4 and 4.1.2), boost version 1.34: -- CODE BEGINS -- #include <iostream> using namespace std; #include "boost/function.hpp" #include "boost/ref.hpp" using namespace boost; #include "boost/lambda/lambda.hpp" #include "boost/lambda/bind.hpp" #include "boost/lambda/if.hpp" using namespace boost::lambda; int main(int argc, char *argv[]) { function<void (int, int)> f = if_(_1 == _2) [ cout << cref("arguments are equal\n") ].else_[ cout << cref("arguments differ\n") ]; f(1, 1); f(1, 2); } -- CODE ENDS -- On g++ 3.3.4 I got a (scarcely readable) error that std::ios_base copy constructor is private (the more recent compiler gave much more trashy output, but I've infered that the reason is probably the same). The error wouldn't appear if I had supplied at least one placeholder to the operator<< in both if's cases in the lambda expression above. Is there any way to overcome this limitation?

Maciek Godek wrote:
function<void (int, int)> f = if_(_1 == _2) [ cout << cref("arguments are equal\n") ].else_[ cout << cref("arguments differ\n") ];
f(1, 1); f(1, 2); } On g++ 3.3.4 I got a (scarcely readable) error that std::ios_base copy constructor is private (the more recent compiler gave much more trashy output, but I've infered that the reason is probably the same).
I think you need to surround the cout with boost::ref, i.e. boost::ref( cout ). The lambda takes a copy of its argument, and you want to make sure that it uses the reference instead. K
participants (2)
-
Kirit Sælensminde
-
Maciek Godek