std::get(std::array)
来自cppreference.com
|
|
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
| template<size_t I, class T, size_t N > T& get( array<T,N>& a ); |
(1) | (C++11 起) |
| template<size_t I, class T, size_t N > T&& get( array<T,N>&& a ); |
(2) | (C++11 起) |
| template<size_t I, class T, size_t N > const T& get( const array<T,N>& a ); |
(3) | (C++11 起) |
从数组中提取
Ithelement元素. Original:
Extracts the
Ith element element from the array. The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
I[0, N)范围内的值必须是一个整数。这是在编译时执行,而不是at()或operator[]().Original:
I must be an integer value in range [0, N). This is enforced at compile time as opposed to at() or operator[]().The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
目录 |
[编辑] 参数
| a | - | 数组,其内容提取
Original: array whose contents to extract The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
[编辑] 返回值
1)参考
2) Ith元素a.Original:
Reference to the
Ith element of a.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
rvalue引用
3) Ith的a元素,除非该元素是左值引用类型,在这种情况下,左值引用被返回.Original:
Rvalue reference to the
Ith element of a, unless the element is of lvalue reference type, in which case lvalue reference is returned.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
const引用的
Ith元素a.Original:
Const reference to the
Ith element of a.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[编辑] 例外
[编辑] 为例
#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"; }
Output:
(1, 2, 3)
[编辑] 另请参阅
| 访问指定的元素 Original: access specified element The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (公共成员函数) | |
| 访问指定的元素与边界检查 Original: access specified element with bounds checking The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (公共成员函数) | |
| tuple访问指定的元素 Original: tuple accesses specified element The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (函数模板) | |
| (C++11) |
访问一个一个 pair元素 Original: accesses an element of a pair The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (函数模板) |