std::get(std::tuple)
Posted thefist11
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了std::get(std::tuple)相关的知识,希望对你有一定的参考价值。
template< std::size_t I, class… Types >typename std::tuple_element<I, tuple<Types…> >::type& get( tuple<Types…>& t ) noexcept; | (1) | (since C++11)(constexpr since C++14) |
template< std::size_t I, class… Types >typename std::tuple_element<I, tuple<Types…> >::type&& get( tuple<Types…>&& t ) noexcept; | (2) | (since C++11)(constexpr since C++14) |
template< std::size_t I, class… Types >typename std::tuple_element<I, tuple<Types…> >::type const& get( const tuple<Types…>& t ) noexcept; | (3) | (since C++11)(constexpr since C++14) |
template< std::size_t I, class… Types >typename std::tuple_element<I, tuple<Types…> >::type const&& get( const tuple<Types…>&& t ) noexcept; | (4) | (since C++11)(constexpr since C++14) |
template< class T, class… Types >constexpr T& get(tuple<Types…>& t) noexcept; | (5) | (since C++14) |
template< class T, class… Types >constexpr T&& get(tuple<Types…>&& t) noexcept; | (6) | (since C++14) |
template< class T, class… Types >constexpr const T& get(const tuple<Types…>& t) noexcept; | (7) | (since C++14) |
template< class T, class… Types >constexpr const T&& get(const tuple<Types…>&& t) noexcept; | (8) | (since C++14) |
eg.
#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";
// type-based access (C++14 or later)
std::cout << "(" << std::get<int>(t) << ", " << std::get<const char*>(t)
<< ", " << std::get<double>(t) << ")\\n";
// Note: std::tie and structured binding may also be used to decompose a tuple
Output:
(1, Foo, 3.14)
(1, Foo, 3.14)
以上是关于std::get(std::tuple)的主要内容,如果未能解决你的问题,请参考以下文章