Boost logo

Boost :

Subject: [boost] [fusion] for_each
From: Christophe Henry (christophe.j.henry_at_[hidden])
Date: 2010-10-05 17:11:34


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?*/
         my_set_type& to_overwrite;


Except that this won't compile because the operator() is required to
be const, which is sad, because it was very simple.

This leaves me with the unattractive option of inverting the set and
the vector inside update. Now, I iterate on the set's elements and
overwrite them when found in the vector.
This is unattractive because 1) the code gets really ugly 2) it could
be slower (the set is bigger) and 3) it has a much bigger compile-time
cost (I resorted to an enable_if of fusion::result_of::find and I make
it short, it is actually much worse).

I thought of using transform, but this will be slower as I will need
to transform every element of the set, even for a vector of size 1.

Am I missing something? If not, would it be possible to remove this constraint?


Boost list run by bdawes at, gregod at, cpdaniel at, john at