array::swap

更新 : 2007 年 11 月

2 つの配列の内容を交換します。

void swap(array& right);

パラメータ

  • right
    内容を交換する配列。

解説

このメンバ関数は、*this と right の間で被制御シーケンスを交換します。N に比例した回数の要素の割り当てとコンストラクタ呼び出しが実行されます。

使用例

 

// std_tr1__array__array_swap.cpp 
// compile with: /EHsc 
#include <array> 
#include <iostream> 
 
typedef std::tr1::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>

名前空間 : std::tr1

参照

参照

<array>

array::operator=