在运行时提升mpl下限
boost mpl lower_bound at runtime
在下面的代码中,我有一个为特定大小构建的类SizedFoo
。类GeneralFoo
保存不同大小的SizedFoos
的数组,然后函数Bar
将找到为大于传入参数的最小大小而初始化的SizedFoo
。我知道boost mpl有下限函数,但它只能与静态已知的值一起使用,有什么方法可以在运行时使用等效函数吗?
class SizedFoo {
...
public:
SizedFoo(size_t size);
void Bar();
}
template<size_t... sizes_in>
class GeneralFoo {
typedef vector_c<size_t, sizes_in...>::type raw_sizes;
typedef sort<raw_sizes>::type sorted_raw_sizes;
typedef unique<sorted_raw_vector, equal_to<_1, _2> >::type sizes;
std::array<SizedFoos*, size<sizes>::type> foos_;
public:
GeneralFoo() {
...
}
void Bar(size_t size) {
//DOESN'T WORK: size is a runtime value
//auto index = lower_bound<sizes, size>::type;
auto index = ... //What goes here?
foos_[index]->Bar();
}
}
mpl是编译时-您试图实现的目标只能在运行时完成,因此需要使用std::lower_bound()
。
相关文章:
- 将 Boost MPL 容器替换为 C++17 功能
- 为什么组合的上限和下限比较的计算结果总是为 true?
- 非推导上下文,如标准库中的"boost::mpl::identity:<T>:type"?
- 上限/下限没有像我预期的那样工作,无法理解为什么
- boost::mpl 不使用(甚至不兼容)std::p air 的原因是什么?
- 为什么下限不适用于向量对
- 从push_front操作中获取常规 MPL 列表
- 以 CPP 为单位设置的下限
- 在 c++ 中的 multiset<pair<int,int> > 中查找下限
- 使用boost :: mpl :: find_if带有自定义谓词
- 提升 MPL 排序模板参数包
- 下限误差
- 检查两个 Boost.MPL 序列是否按任何顺序包含相同的类型
- MPL地图实例化类型
- 使用对象指针向量的下限
- 是否可以使用 static_cast 从可变参数枚举创建 boost::mpl::list_c
- C++高效的整数下限功能
- 下限上限给出相同的结果
- 如果我们有对的矢量,如何进行下限二进制搜索
- 在运行时提升mpl下限