
On Mon, Aug 31, 2009 at 2:20 AM, Marco Guazzone<marco.guazzone@gmail.com> wrote:
Dear all,
Consider this:
---[code]--- #include <boost/mpl/front.hpp> #include <boost/mpl/set.hpp> #include <boost/type_traits/is_same.hpp>
#define BOOST_TEST_MODULE "boost::mpl::set tests" #define BOOST_TEST_DYN_LINK #define BOOST_TEST_MAIN #include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_CASE( mpl_set ) { typedef boost::mpl::set<int,long,char> s; BOOST_CHECK( (boost::is_same<int, boost::mpl::front<s>::type>::value) ); // Test #1 BOOST_CHECK( (boost::is_same<long, boost::mpl::front<s>::type>::value) ); // Test #2 BOOST_CHECK( (boost::is_same<char, boost::mpl::front<s>::type>::value) ); // Test #3 } ---[/code]---
Reading the docs http://www.boost.org/doc/libs/1_40_0/libs/mpl/doc/refmanual/set.html the "front" of a set<t1,t2,...,tn> return the first element type in s which for me is t1 So what I expect is the test to fail on tests #2 and #3 and hence to succeed on test #1
Instead the test fails on tests #1 and #2 and succeeds on test #3.
Looking inside the code I find out this is OK since a setN<T1,..,TN> is defined from TN and set{N-1}<T1,...,T{N-1}>, resulting in TN be the very front element
Anyway, in my opinion this is counterintuitive.
Maybe a note in the document would be helpful.
What do you think?
Thank you very much!
I do not know of set being ordered or any implementation I use (considering that runtime sets are generally hash maps), so I would not expect that to be ordered personally. I would use vector if I want something ordered.