Subject: [boost] [mpl] strange vector_c and integral_c construction
From: Maxim Yanchenko (maximyanchenko_at_[hidden])
Date: 2009-08-11 22:08:37


Hi all,
>
Probably this is well-known and I just failed to find it in the docs and mailing
list.

According to the docs
(http://www.boost.org/doc/libs/1_39_0/libs/mpl/doc/refmanual/integral-sequence-wrapper.html):

  typedef seq_c<T,c1,c2,... cn> s;
  Semantics: s is a sequence seq of integral constant wrappers integral_c<T,c1>,
integral_c<T,c2>, ... integral_c<T,cn>.

Consider the following example:
  
  const int64_t max_int = integer_traits<int>::const_max;
  const int64_t max_int_plus_1 = max_int + 1;
  
  BOOST_MPL_ASSERT(( equal< vector_c< int64_t, 1 >
                          , vector< integral_c< int64_t, 1 > >
> ));

  BOOST_MPL_ASSERT(( equal< vector_c< int64_t, max_int >
                          , vector< integral_c< int64_t, max_int > >
> ));

  BOOST_MPL_ASSERT(( equal< vector_c< int64_t, max_int_plus_1 >
                          , vector< integral_c< int64_t, max_int_plus_1 > >
> ));

The first assert passes, while the second and third fail with the following
error messages (removed repetition of 2147483647l for readability):
test.h:149: error: ************mpl::equal<mpl::vector_c<int64_t, 2147483647l,
2147483647l, ...>, mpl::vector<mpl_::integral_c<int64_t, 2147483647>>,
is_same<true> >::************'
test.h:153: error: ************mpl::equal<mpl::vector_c<int64_t,
-0x00000000080000000l, 2147483647l, ...>, mpl::vector<mpl_::integral_c<int64_t,
2147483648ll>>, is_same<true> >::************'

I consider these errors as a contradiction to the docs statement.
Probably, I configured MPL wrong, as I see in the preprocessed code, where long
is used (boost/mpl/aux_/preprocessed/gcc/vector_c.hpp)

template<
      typename T, long C0 = LONG_MAX, long C1 = LONG_MAX, long C2 = LONG_MAX
    , long C3 = LONG_MAX, long C4 = LONG_MAX, long C5 = LONG_MAX
    , long C6 = LONG_MAX, long C7 = LONG_MAX, long C8 = LONG_MAX
    , long C9 = LONG_MAX, long C10 = LONG_MAX, long C11 = LONG_MAX
    , long C12 = LONG_MAX, long C13 = LONG_MAX, long C14 = LONG_MAX
    , long C15 = LONG_MAX, long C16 = LONG_MAX, long C17 = LONG_MAX
    , long C18 = LONG_MAX, long C19 = LONG_MAX
>
struct vector_c;

I'm using GCC 3.4.6, on Linux-64, compiling 32-bit binary (so int and long are
of same size, and boost::int64_t is bigger than long).

Thanks,
Maxim (to reply in private, please use FirstName.LastName at gmail.com)