Boost logo

Boost Users :

Subject: [Boost-users] [MPL] Front of a set of types
From: Marco Guazzone (marco.guazzone_at_[hidden])
Date: 2009-08-31 04:20:17


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!

Cheers,

-- Marco


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