다음을 통해 공유


swap 함수 <array>

Swaps two arrays.

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

매개 변수

  • Ty
    요소의 형식입니다.

  • N
    배열의 크기입니다.

  • left
    The first array to swap.

  • right
    The second array to swap.

설명

The template function executes left.swap(right).

예제

 

// std_tr1__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); 
    } 
 
  

요구 사항

Header: <array>

네임스페이스: std

참고 항목

참조

array::swap

<array>

array::swap