0
在代碼LOWER_BOUND下面我有被構造爲特定尺寸的類SizedFoo
。類GeneralFoo
包含不同大小的SizedFoos
的數組,然後函數Bar
將找到SizedFoo
,該函數被初始化爲大於傳入參數的最小大小。我知道boost mpl具有lower_bound函數,但只能與靜態已知值一起使用,是否有任何方法可以在運行時使用等價物?升壓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();
}
}