Boost logo

Boost Users :

Subject: Re: [Boost-users] Why does the fusion::set repeated keys?
From: Christopher Schmidt (christopher_at_[hidden])
Date: 2012-05-27 15:39:18


niXman <i.nixman_at_[hidden]> writes:

> In this simple code, I expect that the size of the fusion::set is
> equal to one, because keys are the same.
> Why the size is equal to two?
>
> #include <boost/fusion/container/set.hpp>
> #include <boost/fusion/include/set.hpp>
> #include <boost/fusion/container/set/set_fwd.hpp>
> #include <boost/fusion/include/set_fwd.hpp>
> #include <boost/fusion/sequence/intrinsic/size.hpp>
> #include <boost/fusion/include/size.hpp>
> #include <iostream>
>
> int main() {
> typedef boost::fusion::set<int, int> set1;
> set1 s1;
>
> std::cout
> << "size1 = " << boost::fusion::result_of::size<set1>::type::value
> << ", size2 = " << boost::fusion::size(s1)

BTW. there is no difference between these two invocations. fusion::size
returns result_of::size<>::type::value.

> << std::endl;
> }
>
> http://liveworkspace.org/code/166b54cdd208f7b252bf1f38a1a6ec4b

This is because fusion::set is implemented in terms of a regular
random-access container. This has the advantage that the set implements
the random-access concept and the overall implementation is dead simple.
On the other hand, as you pointed out, the direct pass-through of the
template type arguments results in this issue.

I would not want fusion::set (or any other inbuilt associative
container) to filter duplicate keys on its own. This decreases compile
time. I would not want to have a tagged implementation that catches
such errors automatically, either, because this complicates the source
code without an obvious performance impact. I guess you should simply
do the filtering beforehand on your own, using e.g. Mpl.

        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