1

I just wonder, that when both int_ and integral_c is generated from aux_/integral_wrapper.hpp, also gcc -E output a same class structure, which only differs in class name, why not simply make int_ a type alias to integral_c ?

(such as template <int v> struct int_ : integral_c<int, v> {}; )

------ int_.hpp

...
#include <boost/mpl/int_fwd.hpp>

#define AUX_WRAPPER_VALUE_TYPE int
#include <boost/mpl/aux_/integral_wrapper.hpp>

#endif // BOOST_MPL_INT_HPP_INCLUDED

----- integral_c.hpp

// ...
aux_/integral_wrapper.hpp
#define AUX_WRAPPER_NAME integral_c
#define AUX_WRAPPER_VALUE_TYPE T
#define AUX_WRAPPER_INST(value) AUX_WRAPPER_NAME< T, value >
#include <boost/mpl/aux_/integral_wrapper.hpp>


#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) \
 && !BOOST_WORKAROUND(__BORLANDC__, <= 0x551)
BOOST_MPL_AUX_ADL_BARRIER_NAMESPACE_OPEN
// 'bool' constant doesn't have 'next'/'prior' members
template< bool C >
struct integral_c<bool, C>
{
    BOOST_STATIC_CONSTANT(bool, value = C);
    typedef integral_c_tag tag;
    typedef integral_c type;
    typedef bool value_type;
    operator bool() const { return this->value; }
};
BOOST_MPL_AUX_ADL_BARRIER_NAMESPACE_CLOSE

----- preprocess output. you can see from here that class body of integral_c and int_ has almostly have no difference

template< typename T, T N >
struct integral_c
{
    static const T value = N;





    typedef integral_c type;

    typedef T value_type;
    typedef integral_c_tag tag;
# 72 "boost_1_57_0/boost/mpl/aux_/integral_wrapper.hpp"
    typedef integral_c< T, static_cast<T>((value + 1)) > next;
    typedef integral_c< T, static_cast<T>((value - 1)) > prior;






    constexpr operator T() const { return static_cast<T>(this->value); }
};


template< typename T, T N >
T const integral_c< T, N >::value;


}

namespace mpl_ {

template< int N >
struct int_
{
    static const int value = N;





    typedef int_ type;

    typedef int value_type;
    typedef integral_c_tag tag;
# 72 "boost_1_57_0/boost/mpl/aux_/integral_wrapper.hpp"
    typedef mpl_::int_< static_cast<int>((value + 1)) > next;
    typedef mpl_::int_< static_cast<int>((value - 1)) > prior;






    constexpr operator int() const { return static_cast<int>(this->value); }
};


template< int N >
int const mpl_::int_< N >::value;


}
owensss
  • 121
  • 4
  • I don't know for sure, but it _could_ be because you would expect `std::is_same::next, int_<2>>::value` to be true, which wouldn't work otherwise. – Louis Dionne Dec 03 '14 at 00:51
  • @LouisDionne seems quite reasonable 0v0. But the fact that int_ != integral_c and mpl implicitly use integral_c as the integral_constant part of mpl#iterator still leads to a day-long debug. Where xxx_itereator != xxx_iterator > hence result in a infinite loop – owensss Dec 03 '14 at 03:56
  • 2
    I understand, but it is not possible to have `integral_c` be the same as `int_` in pre-C++11 due to the lack of template aliases. If the `xxx_iterator` thing is your code, then I would suggest defining the `equal` metafunction so it performs a deep equality test. That would both fix your bug and be more semantically correct IMO. – Louis Dionne Dec 05 '14 at 13:05

0 Answers0