M
marius lazer
I have an STL container of functors and I want to execute them using
std::for_each. In the code snippet below the line marked "// good"
works fine and the one marked "// nothing" compiles fine but does
absolutely nothing. Can anyone explain why? I'm using gcc 4.1.1 on
Solaris8.
Thanks,
Marius
#include <iostream>
#include <deque>
#include <boost/lambda/lambda.hpp>
#include <boost/lambda/bind.hpp>
using namespace std;
using namespace boost::lambda;
template <typename C>
void call_all(C& c)
{
std::for_each(c.begin(), c.end(), _1);
// nothing
std::for_each(c.begin(), c.end(), bind(&C::value_type:perator(),
_1)); // good
}
struct Func
{
Func(int s) : i(s) {}
void operator()() const { cerr << __PRETTY_FUNCTION__ << " " << i <<
endl; }
int i;
};
int
main()
{
deque<Func> deq;
deq.push_back(Func(1));
deq.push_back(Func(2));
deq.push_back(Func(3));
call_all(deq);
return 0;
}
std::for_each. In the code snippet below the line marked "// good"
works fine and the one marked "// nothing" compiles fine but does
absolutely nothing. Can anyone explain why? I'm using gcc 4.1.1 on
Solaris8.
Thanks,
Marius
#include <iostream>
#include <deque>
#include <boost/lambda/lambda.hpp>
#include <boost/lambda/bind.hpp>
using namespace std;
using namespace boost::lambda;
template <typename C>
void call_all(C& c)
{
std::for_each(c.begin(), c.end(), _1);
// nothing
std::for_each(c.begin(), c.end(), bind(&C::value_type:perator(),
_1)); // good
}
struct Func
{
Func(int s) : i(s) {}
void operator()() const { cerr << __PRETTY_FUNCTION__ << " " << i <<
endl; }
int i;
};
int
main()
{
deque<Func> deq;
deq.push_back(Func(1));
deq.push_back(Func(2));
deq.push_back(Func(3));
call_all(deq);
return 0;
}