I have two tuples: one with the data I want, and another with a list of indeces for the first tuple. I want to use the second tuple to access items from the first tuple using
std::get, but it doesn't seem to work:
const auto tup = std::make_tuple(4, 5, 6); const auto indeces = std::make_tuple(0, 1, 2); const int index = std::get<0>(indeces); const int value = std::get<index>(tup); // won't compile // value should equal 4
Of course it's obvious why this fails if you consider that
std::get won't return
constexpr int index = std::get<0>(indeces); // won't compile
indeces tuple starts out its life as a parameter pack of ints. I made it into a tuple because I hoped that it would be easier to work with, but this may not be the case. If anyone can see a way of bypassing the
indeces tuple and using the parameter pack ints directly to index the first tuple, that would a welcome answer too.