2012/12/10 Robert Jones <robertgbjones@gmail.com>
The 'Oven' port...

http://dl.dropbox.com/u/1682460/git/OvenToBoost/libs/range/doc/html/range_extension/design_rationale/regular_op.html

makes much of its 'regular' operator, which is used to fix this problem

using boost::lambda::_1;
for_each_(r | filtered(_1 % 2 == 0), f);          // Error! Can't default construct/copy assign
for_each_(r | filtered(regular(_1 % 2 == 0)), f); // OK

However, AFAICS this is not a problem in current-ishBoost (1.47). Has this ever been a problem? Can anyone
comment on its general  provenance?

Thx, Rob.


You can try this code.
for_each_() is possible std::for_each()'s implementation.

#include <iostream>
#include <vector>
#include <boost/lambda/lambda.hpp>
#include <boost/range/adaptor/filtered.hpp>

void disp(int x)
{
    std::cout << x << std::endl;
}

template <class InputIterator, class F>
void for_each_(InputIterator first, InputIterator last, F f)
{
    InputIterator it; // Default Constructible
    it = first; // Copy Assignable
    for (; it != last; ++it) {
        f(*it);
    }
}

template <class SinglePassRange, class F>
void for_each_(const SinglePassRange& rng, F f)
{
    return for_each_(boost::begin(rng), boost::end(rng), f);
}

int main()
{
    using boost::lambda::_1;
    using namespace boost::adaptors;

    const std::vector<int> v = {1, 2, 3, 4, 5};
    for_each_(v | filtered(_1 % 2 == 0), disp);
}

Boost.Lambda and C++11 lambda expression has this issue yet.
And this issue is not a bug. I think this is lambda's specification.

--
>>========================
Akira Takahashi