Boost logo

Boost :

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


On 10/05/2010 02:42 PM, Christophe Henry wrote:
>>> 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.
>
> No, it won't compile ;-)

Hmmm...this simple program compiles for me, as I would expect (g++ 4.4.3):

struct X
{
     int& operator()() const { return y; }
     int& y;
};

int main()
{
     int y = 42;
     const X x = { y };
     int& z = x();
     return 0;
}

which suggests to me that the addition of the const qualifier on
operator() should be okay...

- Jeff


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