A question on for_each() and placeholder.Can any one with kindness help me?

By using Dev-C++, I used lambda expression, I want to know that if I white: typedef std::vector<int> vect1; std::vector<vect1> vect2; vect2 vect2Instance; then std::for_each(vect2Instance.begin(),vect2Instance.end(), std::for_each(_1.begin(),_1.end(),_1+=2)); is legal or not? And if legal ,Does the first two _1's mean a number in vect2 (i.e. a vect1) and the last _1 is a number in vect1(i.e. a int)? Can any one with kindness help me?

AMDG fmingu wrote:
By using Dev-C++, I used lambda expression, I want to know that if I white: typedef std::vector<int> vect1; std::vector<vect1> vect2; vect2 vect2Instance; then std::for_each(vect2Instance.begin(),vect2Instance.end(), std::for_each(_1.begin(),_1.end(),_1+=2)); is legal or not? And if legal ,Does the first two _1's mean a number in vect2 (i.e. a vect1) and the last _1 is a number in vect1(i.e. a int)? Can any one with kindness help me?
No. It isn't legal. std::for_each cannot return a function object.
Boost.Lambda provides lazy wrappers for some algorithms.
Here's a complete sample. Note that you can't use boost::lambda::call_begin
because it always returns a const_iterator. (Which I will fix shortly).
#include
::type type; }; template<class T> typename boost::range_iterator<T>::type operator()(T& t) const { return(boost::begin(t)); } };
struct end { template<class Args> struct sig { typedef typename boost::range_iterator< typename boost::tuples::element<1, Args>::type
::type type; }; template<class T> typename boost::range_iterator<T>::type operator()(T& t) const { return(boost::end(t)); } };
int main() {
std::vector
participants (2)
-
fmingu
-
Steven Watanabe