
Jean-Louis Leroy schrieb:
Jean-Louis Leroy wrote:
How can I create a map that has the same content as another rmap, except for a given key which has a new associated value ? I'm looking for something like replace_key<Key>(Sequence, Value) in the doc but I cannot find it. I think I can build it with push_back(erase_key<Key>(seq), make_pair<Key>(newval)) but if it already exists...
I'm encountering difficulties while trying to implement this. Consider :
template<class K> struct replace_at_key { template<typename Any> bool operator()(Any) const { return false; } template<class V> bool operator()(boost::fusion::pair
) const { return true; } }; void test() { using namespace boost::fusion;
typedef map< pair
, pair > map_type; map_type m( make_pair<int>("X") , make_pair<double>("Men"));
BOOST_AUTO(v, boost::fusion::as_vector( replace_if(m, replace_at_key<int>(), make_pair
("Z")))); as_map(v); // error : reference to reference }
I get compiler errors (msvc9 and g++ 4.4.1) because it's trying to form a reference to a reference. Indeed, when I look inside v with the debugger I see that the type of v.vec.m1 is `const pair
&' (note : reference). And m1 is passed by reference in the internals of fusion. Hence the error. Am I doing something wrong here ?
Thanks, J-L
Yeah, that's definitely a bug of fusion. Please file a bug report. For now you can use my fusion port, it has this bug fixed ;) -Christopher