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
niXman
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
#include #include #include #include #include #include <iostream> int main() { typedef boost::fusion::set
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