2013-11-20 37 views
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(); 
    } 
} 

回答

0

MPL是編譯的時候 - 你想什麼來實現,只能在運行時完成,對於您將需要使用std::lower_bound()