Boost logo

Boost :

Subject: Re: [boost] [fusion] Problems with push_back/push_front/insert into map
From: Christopher Schmidt (mr.chr.schmidt_at_[hidden])
Date: 2010-08-27 03:49:55


Alexander Fokin schrieb:
> Consider the following program:
>
> #include <iostream>
> #include <boost/fusion/algorithm.hpp>
> #include <boost/fusion/container.hpp>
> #include <boost/fusion/sequence.hpp>
>
> int main() {
> using namespace boost::fusion;
>
> map<> m;
>
> result_of::push_back<const map<>, pair<int, int> >::type m1 =
> push_back(m, pair<int, int>(0));
>
> bool b1 = has_key<int>(m1); // b1 == false
> bool b2 = has_key<int>(as_map(m1)); // b2 == true
> int sz = size(m1); // sz == 1
>
> return 0;
> }
>
> According to documentation [1], result of push_back is a model of
> Associative Sequence if its sequence parameter implements the
> Associative Sequence model. Therefore, I'd expect the variable b1 to
> be evaluated to true, not false. Is this the intended behavior?
>
> I get the same results with push_front and insert. Tested with boost
> 1.43 and 1.44.
>
> [1] http://www.boost.org/doc/libs/1_44_0/libs/fusion/doc/html/fusion/algorithm/transformation/functions/push_back.html

The documentation is wrong. fusion::push_back constructs a
fusion::joint_view<seq, fusion::single_view<val> const> . This joint
view is only associative iff both of its underlying sequences are. The
fusion::single_view is not associative, though.
I think fusion::single_view should be specialized for (possibly
cv-ref-qualified) fusion::pair's - and these specializations should add
the associative trait.

-Christopher


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