typedef std::tuple< int, double > Tuple;
Tuple t;
int a = std::get<0>(t);
double b = std::get<1>(t);
for( size_t i = 0; i < std::tuple_size<Tuple>::value; i++ ) {
std::tuple_element<i,Tuple>::type v = std::get<i>(t);// will not compile because i must be known at compile time
}
I know it is possible to write code for get std::get working (see for example iterate over tuple ), is it possible to get std::tuple_element working too?
Some constraints (they can be relaxed):
no variadic templates, no Boost
No, this is not possible the way you describe it. Basically, you’d have to write your code for every possible runtime-value of
iand then use some dispatching-logic (e.g.switch(i)) to run the correct code based on the actual runtime-value ofi.In practice, it might be possible to generate the code for the different values of
iwith templates, but I am not really sure how to do this, and whether it would be practical. What you are describing sounds like a flawed design.