2

假设我有一个boost::mpl::list< A, B, C ...>.

在运行时给定索引值,我如何访问其中一种类型?甚至可能吗?

4

1 回答 1

2

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

您基本上必须遍历整个列表并引入某种条件:例如:

struct F {
    void operator(T &t) {
        if (i_ == index) ...
        ++i;
    }
    int index = ...;
    int i_ = 0;
};
for_each< L >( F(index) );
于 2011-05-13T18:51:13.227 回答