|
Boost : |
From: Marius Lazer (Marius.Lazer_at_[hidden])
Date: 2006-09-15 11:56:37
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? Are there better ways of doing this?
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::operator(), _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;
}
**********************************************************************
The information in this Internet e-mail is confidential and may be legally privileged. No confidentiality or privilege is waived or lost by any mistransmission.
It is intended solely for the addressee. Access to this Internet e-mail by anyone else
is unauthorized and any disclosure, copying, distribution or any action taken or omitted
to be taken in reliance on it, is prohibited and may be unlawful.
When addressed to our clients any opinions or advice contained in this Internet e-mail are
subject to the terms and conditions expressed in any applicable documentation or market
practices governing the relationship between the sender and its clients.
Any views expressed in this message are those of the individual sender except where they
are stated to be the views of the company.
**********************************************************************
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk