std::get(std::array)
STD::获取%28 std::Array%29
template< size_t I, class T, size_t N > constexpr T& get( array | (1) | (since C++11) |
---|---|---|
template< size_t I, class T, size_t N > constexpr T&& get( array<T,N>&& a | (2) | (since C++11) |
template< size_t I, class T, size_t N > constexpr const T& get( const array<T,N>& a | (3) | (since C++11) |
template< size_t I, class T, size_t N > constexpr const T&& get( const array<T,N>&& a | (4) | (since C++17) |
提取Ith
元素的元素。
I
必须是范围内的整数值。[0, N)
这是在编译时强制执行的,而不是at()
或operator[]
...
参数
a | - | array whose contents to extract |
---|
返回值
引用Ith
元素a
...
例外
noexcept
规格:
noexcept
注记
过载标记为constexpr
从C++14开始。
例
二次
#include <iostream>
#include <array>
int main()
{
std::array<int, 3> arr;
// set values:
std::get<0>(arr) = 1;
std::get<1>(arr) = 2;
std::get<2>(arr) = 3;
// get values:
std::cout << "(" << std::get<0>(arr) << ", " << std::get<1>(arr)
<< ", " << std::get<2>(arr) << ")\n";
}
二次
产出:
二次
(1, 2, 3)
二次
另见
operator[] | access specified element (public member function) |
---|---|
at | access specified element with bounds checking (public member function) |
std::get(std::tuple) | tuple accesses specified element (function template) |
std::get(std::pair) (C++11) | accesses an element of a pair (function template) |
std::get(std::variant) (C++17) | reads the value of the variant given the index or the type (if the type is unique), throws on error (function template) |
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。