Boost logo

Boost :

Subject: Re: [boost] [fusion] for_each
From: Joel de Guzman (joel_at_[hidden])
Date: 2010-10-05 19:41:23


On 10/6/10 5:32 AM, Jeffrey Lee Hellrung, Jr. wrote:
> 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)...

Jeffrey, I don't see that here (F is received by value):
http://tinyurl.com/2vdao6r. Do you?

Henry, could you provide some code I can try? const should be OK and
I don't see any reason why not.

Regards,

-- 
Joel de Guzman
http://www.boostpro.com
http://spirit.sf.net

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