我试图在代码中使用and_,而且它的返回类型有问题。我试图将它与接受并返回true_type或false_type的其他元编程结构一起使用,我也使用SFINAE重载这些类型。boost::mpl::and_和boost::mpl::or_从大部分mpl返回不同的类型。至少在我看来是这样的。
mpl_::failed************ boost::is_same<mpl_::bool_<true>, boost::integral_constant<bool, true> >::************)那么,我如何编写下面的代码以传递断言呢?
template <typename T, typename U>
void foo(const T& test, const U& test2)
{
typedef typename boost::mpl::and_<typename utilities::is_vector<T>, typename utilities::is_vector<U> >::type asdf;
BOOST_MPL_ASSERT(( boost::is_same<asdf, boost::true_type::value> ));
}
void fooer()
{
std::vector<int> test1;
std::vector<int> test2;
foo(test1, test2);
}发布于 2013-09-01 15:59:19
BOOST_MPL_ASSERT需要一个元功能谓词,即其返回类型可以解释为"true“或"false”的元函数,即其返回类型为boost::mpl::true_或boost::mpl::false。
正如定义的那样,类型"asdf“关注这个需求,因此没有必要显式地检查它与"true”的任何元编程抽象,编写BOOST_MPL_ASSERT(( asdf ))完全符合您的要求。
当然,如果您愿意,您也可以显式地将它与"true“进行比较,但是必须将其与boost::mpl::true_进行比较,这与您可能预期的boost::true_type类型不完全相同,因此出现了混乱!
发布于 2013-09-05 17:33:27
只使用C++11可能更容易:
static_assert(asdf::value, "T and U aren't both vectors!");或
static_assert(std::is_same<asdf, boost::true_>::value, "T and U aren't both vectors!");https://stackoverflow.com/questions/17957728
复制相似问题