Boost logo

Boost :

Subject: Re: [boost] [fusion] for_each
From: Jeffrey Lee Hellrung, Jr. (jhellrung_at_[hidden])
Date: 2010-10-05 17:32:09


On 10/05/2010 02:11 PM, Christophe Henry wrote:
> Hi,
>
> I have 2 fusion containers: a small vector (my_vec) and a bigger set
> (my_set). I want to overwrite the elements of the set with elements
> from the vector whenever they have the same type. Sounds simple:
>
> struct update
> {
> update(my_set_type& to_overwrite_):to_overwrite(to_overwrite_){}
> template<typename T>
> void operator()(T& elt) /*const?*/
> {
> boost::fusion::at_key<T>(to_overwrite)=elt;
> }
> my_set_type& to_overwrite;
> };
>
> boost::fusion::for_each(my_vec,update(my_set));
>
> Except that this won't compile because the operator() is required to
> be const, which is sad, because it was very simple.

And it won't compile *with* the const? I don't think the const'ness of
the member function affects the const'ness of the referent of to_overwrite.

That said, it does look the documentation for boost::fusion::for_each
(indicating that F is received by value) contradicts the source code
(where F is received by reference-to-const)...

- Jeff


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk