|
Boost Users : |
Subject: Re: [Boost-users] [fusion] "modify" value in map
From: Christopher Schmidt (mr.chr.schmidt_at_[hidden])
Date: 2009-09-27 06:00:02
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<K, V>) const
> { return true; }
> };
>
> void test() {
> using namespace boost::fusion;
>
> typedef map<
> pair<int, std::string>
> , pair<double, std::string> >
> 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<int, std::string>("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<double, string>&' (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
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net