Boost logo

Boost Users :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2004-11-30 11:26:13


John.Wismar_at_[hidden] 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 <class Container, class Function>
> 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)().


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net