开发者

How to get a type relative to a runtime index?

开发者 https://www.devze.com 2023-03-05 13:57 出处:网络
Let\'s say I have a boost::mpl::list< A, B, C ...>. How do I access one of those typ开发者_运维技巧es given an index value at runtime? Is it even possible?http://www.boost.org/doc/libs/release/

Let's say I have a boost::mpl::list< A, B, C ...>.

How do I access one of those typ开发者_运维技巧es given an index value at runtime? Is it even possible?


http://www.boost.org/doc/libs/release/libs/mpl/doc/refmanual/for-each.html

you basically have to iterate over the entire list and introduce some sort of conditional: eg:

struct F {
    void operator(T &t) {
        if (i_ == index) ...
        ++i;
    }
    int index = ...;
    int i_ = 0;
};
for_each< L >( F(index) );
0

精彩评论

暂无评论...
验证码 换一张
取 消