0
#include <iostream>
#include <string>
#include <tuple>
 
int main()
{
    auto t = std::make_tuple(1, "Foo", 3.14);
    // index-based access
    std::cout << "(" << std::get<0>(t) << ", " << std::get<1>(t)
              << ", " << std::get<2>(t) << ")\n";
}

Is it possible to use a variable for the index to access a tuple element instead of a constant?

Bob
  • 4,576
  • 7
  • 39
  • 107

0 Answers0