[mpl] strange vector_c and integral_c construction

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-sequenc...): 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)

Maxim Yanchenko wrote:
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-sequenc...):
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)
gcc-4.3.3 and 4.4.0 compile this example fine. BR, Dmitry

Hi Dmitry,
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).
gcc-4.3.3 and 4.4.0 compile this example fine.
For gcc 3.4.6, it compiles fine too when I compile 64-bit binary, but fails on 32 . This problem involves three types: int, long, and int64_t (long is in vector_c definition). Of course, if long and int64_t are same, the problem won't appear. For my system, the sizeofs of the types are: 32bit: int = long < int64_t (fail) 64bit: int < long = int64_t (ok) What about the system you've tried? Thanks, Maxim (to reply in private, please use FirstName.LastName at gmail.com)

Maxim Yanchenko wrote:
This problem involves three types: int, long, and int64_t (long is in vector_c definition). Of course, if long and int64_t are same, the problem won't appear.
For my system, the sizeofs of the types are: 32bit: int = long < int64_t (fail) 64bit: int < long = int64_t (ok)
What about the system you've tried?
I had a similar pb. I think that, internally, vector_c only use long and don't check for 64 bits actual int64_t. -- ___________________________________________ Joel Falcou - Assistant Professor PARALL Team - LRI - Universite Paris Sud XI Tel : (+33)1 69 15 66 35

Maxim Yanchenko wrote:
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).
long is the biggest integral type as far as standard C++ is concerned. The issue comes from the fact the "long long" extension is not supported by Boost.MPL. So, strictly speaking, it's more of a lacking feature than a bug.
participants (4)
-
Dmitry Goncharov
-
joel
-
Mathias Gaunard
-
Maxim Yanchenko