Global function std::get

The global function std::get can be used for all of std::tuple, std::pair, std::variant and std::array.

std::get<Index>

When std::get is used with an index, as in std::get<1>(v) it returns the value at the corresponding index in a std::tuple, std::pair, or std::array.

std::get<Type>

When std::get is used with a type, as in std::get<int>(v) , the corresponding value in a std::tuple, std::pair or std::variant is returned. In the case of std::variant, an exception is thrown if the variant doesn't currently hold that type. Note that if v is a std::tuple and Type is contained more than once, you have to use the index to access the type.

Get C++ High Performance now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.