【发布时间】:2023-03-29 04:03:01
【问题描述】:
谁能告诉我为什么下面的断言失败?
问题1:
typedef mpl::map<mpl::pair<int, unsigned>, mpl::pair<char, unsigned char> > m;
typedef mpl::fold<m, mpl::vector<>, mpl::push_back<mpl::_1, mpl::first<mpl::_2>>>::type keys;
BOOST_STATIC_ASSERT((std::is_same<boost::mpl::vector<int, char>, keys>::value == 1));
问题2: 如果我想编写一个折叠函数来生成指向地图键的指针的 mpl::vector,我应该怎么写?
template <typename T>
pointer_type {
typedef T* pointer_type;
}
typedef mpl::fold<m, mpl::vector<>, mpl::push_back<mpl::_1, pointer_type<mpl::first<mpl::_2>>>::type>::pointer_type
> keys;
似乎不起作用。 mpl::_2 从未被评估过。
【问题讨论】:
标签: templates boost template-meta-programming