【发布时间】:2012-01-18 22:41:04
【问题描述】:
可以迭代 boost 或 std 元组,但我可以按照运行时确定的顺序进行迭代,同时仍保留类型信息吗?
假设我的元组中填充了Foo 类型的对象:
#include <tuple>
using namespace std;
template <typename ...> void bar(); // Definition omitted.
template <typename ... Ts>
struct Foo {
void doit() { bar<Ts...>(); }
int rank;
};
int main(int argc, char *argv[])
{
auto tup = make_tuple(Foo<int,double>(),
Foo<bool,char,float>());
get<0>(tup).rank = 2;
get<1>(tup).rank = 1;
return 0;
}
我希望能够遍历Foo 类型的列表,调用它们的doit 方法,但是按照由rank 成员的值定义的任意顺序。
【问题讨论】:
标签: c++ templates c++11 tuples boost-tuples