如何有条件地添加增强 MPL
How do I conditionally add with boost MPL?
我正在尝试根据提供的类型参数评估位集的值。我现在的功能是这样的:
template <class Set, class PartialSet>
constexpr auto tupleBitset() {
using type =
typename mpl::fold<
PartialSet,
mpl::integral_c<unsigned long long, 0>,
mpl::eval_if<
mpl::has_key<Set, mpl::_2>,
mpl::plus<
mpl::_1,
mpl::integral_c<unsigned long long, 1ull << getIndex<Set, mpl::_2>()>
>,
mpl::_1
>
>::type;
return std::bitset<mpl::size<Set>::value>(type::value);
}
基本上,该函数意图的要点是能够创建一个位集,其位是基于Set
和PartialSet
的交集创建的,两者都是mpl::set
s。还提供了getIndex
的功能:
template <class Set, class Index>
constexpr auto getIndex() {
return mpl::distance<
typename mpl::begin<Set>::type,
typename mpl::find<Set, Index>::type
>::type::value;
}
这种方法似乎不起作用,编译错误评估如下:
'value' is not a member of 'boost::mpl::same_as<U1> in 'not.hpp'
'C_': invalid template argument for 'boost::mpl::aux::not_impl', expected compile-time constant expression in not.hpp
左移是否有可能不是编译时常数?
似乎问题出在 getIndex
的调用,因为mpl::_2
没有被替换。不幸的是,我不知道如何强制替换。
问题是您将place_holder传递给函数 getIndex
。
你可以像这样在结构中转换你的函数
template< typename Set, typename Index > struct getIndex
: mpl::integral_c<unsigned long long, ( mpl::distance<
typename mpl::begin<Set>::type,
typename mpl::find<Set, Index>::type
>::type::value )>
{
};
template <class Set, class PartialSet>
constexpr auto tupleBitset() {
using type =
typename mpl::fold<
PartialSet,
mpl::integral_c<unsigned long long, 0>,
mpl::eval_if<
mpl::has_key<Set, mpl::_2>,
mpl::plus<
mpl::_1,
mpl::shift_left<mpl::integral_c<unsigned long long, 1ull>,
getIndex<Set, mpl::_2>>
>,
mpl::_1
>
>::type;
return std::bitset<mpl::size<Set>::value>(type::value);
}
演示
相关文章:
- 无法将结构注册为增强几何体3D点
- 增强基于 XML class_id的反序列化
- 增强精神解析器规则以检测语句中的特殊结尾
- C++ 使用增强正则表达式库时断言崩溃
- 增强精神 X3:错误:在"..."中没有名为"大小"的类型
- 如何包装(撰写)增强 hana 地图并访问括号运算符(运算符 [])?
- 有没有办法在C ++中检测汉字?(使用增强)
- 如何将增强MSM与增强信号结合使用?
- 将 Boost MPL 容器替换为 C++17 功能
- 如何使用增强::几何计算多边形的旋转固体体积?
- 复制部分文件的C++/增强方式
- 增强 ASIO 和串行端口异步读取
- 增强 Hana index_if和类型
- 在增强MPL和Fusion中启用任意尺寸的集合
- 如何有条件地添加增强 MPL
- 增强 MPL 将每个元素包装在一个集合中
- 增强mpl序列模式匹配
- 为每个函数和自由函数增强mpl
- 增强MPL嵌套lambda
- 增强MPL转换序列"真实"类型