首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::get(std::array)

template< size_t I, class T, size_t N > constexpr T& get( array<T,N>& a );

(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开始。

二次

代码语言:javascript
复制
#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";
}

二次

产出:

二次

代码语言:javascript
复制
(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)

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com