get 函数 <array>

返回对 arr[Idx]的引用。

template<int Idx, class Ty, std::size_t N>
    Ty& get(array<Ty, N>& arr);
template<int Idx, class Ty, std::size_t N>
    const Ty& get(const array<Ty, N>& arr);

参数

  • Idx
    元素偏移。

  • Ty
    元素的类型。

  • N
    数组大小。

  • arr
    从选定的数组。

示例

 

// std_tr1__array__get.cpp 
// compile with: /EHsc 
#include <array> 
#include <iostream> 
 
typedef std::array<int, 4> Myarray; 
int main() 
    { 
    Myarray c0 = {0, 1, 2, 3}; 
 
// display contents " 0 1 2 3" 
    for (Myarray::const_iterator it = c0.begin(); 
        it != c0.end(); ++it) 
        std::cout << " " << *it; 
    std::cout << std::endl; 
 
// display odd elements " 1 3" 
    std::cout << " " << std::get<1>(c0); 
    std::cout << " " << std::get<3>(c0); 
    std::cout << std::endl; 
 
    return (0); 
    } 
 
  

要求

数组页眉: <>

命名空间: std

请参见

参考

<array>

tuple_element 类 <array>