John.Wismar@autozone.com wrote:
If I change the declaration of for_all to take the container by const reference, I get errors [See Error 1 pasted in below]:
using namespace boost::lambda;
class Foo { public: void print() { std::cout << "Foo::print()\n"; } };
template
Function for_all(Container const &cont, Function f) { return std::for_each(cont.begin(), cont.end(), f); }
You are trying to invoke the non-const member function Foo::print on a const Foo.
Example 2: It looks from the docs like I should be able to rewrite the bind expression above using operator ->*, like so:
for_all(vec, (&_1 ->* &Foo::print));
And, in fact this compiles cleanly (regardless of whether the container is passed by value or by const reference). Foo::print() never gets called, though. What am I doing wrong or not understanding here?
You didn't call the function: (&_1->*&Foo::print)().