std::get(std::tuple) (3) - Linux Manuals
std::get(std::tuple): std::get(std::tuple)
NAME
std::get(std::tuple) - std::get(std::tuple)
Synopsis
template< std::size_t I, class... Types > (since C++11)
typename std::tuple_element<I, tuple<Types...> >::type& (1) (constexpr since C++14)
get( tuple<Types...>& t ) noexcept;
template< std::size_t I, class... Types > (since C++11)
typename std::tuple_element<I, tuple<Types...> >::type&& (2) (constexpr since C++14)
get( tuple<Types...>&& t ) noexcept;
template< std::size_t I, class... Types > (since C++11)
typename std::tuple_element<I, tuple<Types...> >::type const& (3) (constexpr since C++14)
get( const tuple<Types...>& t ) noexcept;
template< std::size_t I, class... Types > (since C++11)
typename std::tuple_element<I, tuple<Types...> >::type const&& (4) (constexpr since C++14)
get( const tuple<Types...>&& t ) noexcept;
template< class T, class... Types > (5) (since C++14)
constexpr T& get(tuple<Types...>& t) noexcept;
template< class T, class... Types > (6) (since C++14)
constexpr T&& get(tuple<Types...>&& t) noexcept;
template< class T, class... Types > (7) (since C++14)
constexpr const T& get(const tuple<Types...>& t) noexcept;
template< class T, class... Types > (8) (since C++14)
constexpr const T&& get(const tuple<Types...>&& t) noexcept;
1-4) Extracts the Ith element from the tuple. I must be an integer value in [0, sizeof...(Types)).
5-8) Extracts the element of the tuple t whose type is T. Fails to compile unless the tuple has exactly one element of that type.
Parameters
t - tuple whose contents to extract
Return value
A reference to the selected element of t.
Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR Applied to Behavior as published Correct behavior
LWG_2485 C++11 there are no overloads for const tuple&& the overloads are added
Example
// Run this code
Output:
See also
std::get(std::array) (function template)
std::get(std::pair) accesses an element of a pair
(C++11)
std::get(std::variant) reads the value of the variant given the index or the type (if the type is unique), throws on error
(C++17)