开发者

How to get a type relative to a runtime index?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜