[Boost-users] Why does the fusion::set repeated keys?

5 views
Skip to first unread message

niXman

unread,
May 25, 2012, 10:04:25 PM5/25/12
to boost...@lists.boost.org
Hi,

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)
<< std::endl;
}

http://liveworkspace.org/code/166b54cdd208f7b252bf1f38a1a6ec4b

Thanks!


--
Regards,
  niXman
___________________________________________________
Dual-target(i686/x86_64) MinGW compiler for i686/x86_64 hosts:
  http://sourceforge.net/projects/mingwbuilds/
_______________________________________________
Boost-users mailing list
Boost...@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users

Christopher Schmidt

unread,
May 27, 2012, 3:39:18 PM5/27/12
to boost...@lists.boost.org
niXman <i.ni...@gmail.com> 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
Reply all
Reply to author
Forward
0 new messages