<array> 함수

배열 헤더에는 <두 개의 비 멤버 함수 getswap배열 개체에서 작동하는 함수가 포함됩니다.>

get
swap

get

배열의 지정된 요소에 대한 참조를 반환합니다.

template <int Index, class T, size_t N>
constexpr T& get(array<T, N>& arr) noexcept;

template <int Index, class T, size_t N>
constexpr const T& get(const array<T, N>& arr) noexcept;

template <int Index, class T, size_t N>
constexpr T&& get(array<T, N>&& arr) noexcept;

매개 변수

Index
요소 오프셋입니다.

T
요소의 형식입니다.

N
배열의 요소 수입니다.

도착
선택할 배열입니다.

예시

#include <array>
#include <iostream>

using namespace std;

typedef array<int, 4> MyArray;

int main()
{
    MyArray c0 { 0, 1, 2, 3 };

    // display contents " 0 1 2 3"
    for (const auto& e : c0)
    {
        cout << " " << e;
    }
    cout << endl;

    // display odd elements " 1 3"
    cout << " " << get<1>(c0);
    cout << " " << get<3>(c0) << endl;
}
0 1 2 3
1 3

swap

배열 개체를 std::swap 교환하는 비 멤버 템플릿 특수화입니다.

template <class Ty, std::size_t N>
void swap(array<Ty, N>& left, array<Ty, N>& right);

매개 변수

Ty
요소의 형식입니다.

N
배열 크기입니다.

left
교환할 첫 번째 배열입니다.

right
교환할 두 번째 배열입니다.

설명

이 템플릿 함수는 left.swap(right)을 실행합니다.

예시

// std__array__swap.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;

    Myarray c1 = { 4, 5, 6, 7 };
    c0.swap(c1);

    // display swapped contents " 4 5 6 7"
    for (Myarray::const_iterator it = c0.begin();
        it != c0.end(); ++it)
        std::cout << " " << *it;
    std::cout << std::endl;

    swap(c0, c1);

    // display swapped contents " 0 1 2 3"
    for (Myarray::const_iterator it = c0.begin();
        it != c0.end(); ++it)
        std::cout << " " << *it;
    std::cout << std::endl;

    return (0);
}
0 1 2 3
4 5 6 7
0 1 2 3

참고 항목

<array>