【发布时间】:2010-03-05 16:08:07
【问题描述】:
我需要一个支持类型递归的类似 mpl::equal 的过程。
namespace mpl = boost::mpl;
BOOST_MPL_ASSERT(( mpl::equal<
mpl::vector<int, char>,
typename mpl::push_back<mpl::vector<int>, char>::type > )); // OK
上面的编译很好,但是如果我在 mpl::transform 或 mpl::fold 中使用它,visual studio 2010 rc1 会报错。
typedef mpl::vector<
mpl::vector<int, char>,
mpl::vector<char, char>> type_1;
typedef mpl::transform<
mpl::vector<
mpl::vector<int>,
mpl::vector<char>>,
mpl::push_back<mpl::_, char>>::type type_2;
BOOST_MPL_ASSERT(( mpl::equal<type_1, type_2> )); // FAILS
但是,这些工作...
BOOST_MPL_ASSERT(( mpl::equal<
typename mpl::at_c<type_1, 0>::type,
typename mpl::at_c<type_2, 0>::type> )); // OK
BOOST_MPL_ASSERT(( mpl::equal<
typename mpl::at_c<type_1, 1>::type,
typename mpl::at_c<type_2, 1>::type> )); // OK
是 mpl::equal 不适用于动态生成的递归类型,还是我的语法有问题?
任何建议将不胜感激。
【问题讨论】:
标签: c++ templates boost boost-mpl