STL get<IDX|TYPE>(OBJ)
and set<IDX|TYPE>(OBJ,VAL)
in C++
Several STL global functions grant access by index or, since C++14, by type, for (array, span, pair, tuple, variant within their (static) sizes.):
-
tuples:
auto t = std::make_tuple(1, "Foo", 3.14); std::cout << "( " << get<0>(t); // access by index std::cout << "( " << get<int>(t); // access by type
-
variants:
std::variant<int, float> v{12}, w; std::cout << std::get<int>(v) < '\n';
-
pairs:
std::pair <int,char> foo (10,'x'); std::get<0>(foo) = 50;