While upgrading to a newer compiler and resolving compiler errors I realized that boost::fusion::for_each
requires that the function object passed in has the operator const
.
Example from Boost:
struct increment
{
template<typename T>
void operator()(T& t) const
{
++t;
}
};
...
vector<int,int> vec(1,2);
for_each(vec, increment());
This has of course not changed. I didn't realized it's different to std::for_each
, which does not require the operator to be const
.
struct increment
{
template<typename T>
void operator()(T& t) // no const here!!!
{
++t;
}
};
std::vector<int> numbers;
std::for_each(numbers.begin(), numbers.end(), increment());
Is there any obvious reason for requiring const
? I obviously cannot change that, but I'd like to understand why these two differ.
Thanks for any insights and explanations!