Boost logo

Boost Users :

From: Tobias Schwinger (tschwinger_at_[hidden])
Date: 2007-03-20 03:35:41


Joel de Guzman wrote:
> Eric Niebler wrote:
>> Tobias Schwinger wrote:
>>> Christian Henning wrote:
>>>> Hi there, is it possible to have a stateful functor object when using
>>>> fusion::for_each() loop.
>>>>
>>>> I would like to to the following:
>>>>
>>> <snip code>
>>>
>>> for_each takes the function object by reference to const, so you have to
>>> const qualify operator() and make the data members mutable so you can
>>> change them anyway.
>>
>> IMO, this is a bug in Fusion. There should be an overload of for_each
>> that takes a function object by non-const reference.

For the function invokers I use by-value parameters and the templates
are designed to allow explicitly specified template arguments to use
references instead. The reason was that by-value arguments can be more
efficient for small function objects (tracking side effects) and
function pointers.

It might be worthwhile to consider this scheme as an alternative to
overloading, especially for algorithms which call back multiple times.

>> Stateful predicates
>> should be supported, and Fusion should be explicit about where and when
>> predicates are copied, so that the state doesn't get messed up.
>
> I agree. This is one of the todo items. Noted and added in the queue.

No doubt here.

Regards,
Tobias


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net