我只是想知道,当int_
和integral_c
都是从aux_/integral_wrapper.hpp
生成的时候,gcc -E输出一个相同的类结构,只在类名中有所不同,为什么不简单make int_为integral_c的类型别名?
(例如
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
-----预处理输出。你可以从这里看到integral_c和int_的类体几乎没有区别
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;
}