В приведенном ниже коде воспроизводится поведение библиотеки boost MPL, которое я действительно не понимаю:
#include <boost/type_traits/is_same.hpp>
#include <boost/mpl/int.hpp>
#include <boost/mpl/plus.hpp>
using namespace boost;
int main() {
typedef mpl::int_<1> one;
typedef mpl::int_<2> two;
typedef mpl::int_<3> three;
// The following line breaks compilation...
// static_assert( is_same< mpl::plus<one,two>::type, three >::type::value, "Not the same type");
// ...while this works
static_assert( mpl::plus<one,two>::type::value == three::value , "Not the same value");
return 0;
}
У меня есть вопрос: почему mpl::plus<one,two>::type
не того же типа, что и three
?
Я столкнулся с этой проблемой, пытаясь решить упражнения в конце главы 3 метапрограммирования шаблонов C++. Я уже пытался заглянуть в <boost/mpl/plus.hpp>
и входящие в него включения, но код был слишком сложен, чтобы я мог его понять.