【发布时间】:2018-09-30 12:15:17
【问题描述】:
我正在使用 boost::hana,我想过滤一个 boost::hana::set。
#include <boost/hana.hpp>
#include <type_traits>
int main(){
using namespace boost::hana;
auto a = make_set(1,'a',3);
auto b = remove_if(a, [](const auto& x){return bool_c<std::is_same_v<decltype(x), char>>;});
// expects b to be make_set(1, 3);
}
这会导致 static_assert 失败。它告诉我:
static assertion failed: hana::remove_if(xs, predicate) requires 'xs' to be a MonadPlus
static_assert(hana::MonadPlus<M>::value,
为什么会失败?为什么集合不能是 MonadPlus,即使定义了空集合和连接操作?
【问题讨论】:
-
可能是因为集合不是序列,因为
sets 必须包含唯一元素。如果你想要更具体的东西,那么你可以在hana的代码中找到hana::MonadPlus的定义,然后再返回看看hana::set缺少哪些先决条件。 -
这是一个完全合法且可以回答的问题。为什么它被否决了?
标签: c++ template-meta-programming boost-hana