Why does the fusion::set repeated keys?
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/
niXman <i.nixman@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
participants (2)
-
Christopher Schmidt
-
niXman