• Class / Function / Type

      std::
    • Header file

      <>
    • Other / All

    最終更新日時(UTC):
    が更新

    履歴 編集

    function template
    <deque>

    std::swap (非メンバ関数)

    namespace std {
      template <class T, class Allocator>
      void swap(deque<T,Allocator>& x, deque<T,Allocator>& y);
    
      template <class T, class Allocator>
      void swap(deque<T,Allocator>& x, deque<T,Allocator>& y)
        noexcept(noexcept(x.swap(y)));                         // C++17
    }
    

    概要

    2つのdequeオブジェクトを入れ替える

    効果

    x.swap(y)

    戻り値

    なし

    #include <iostream>
    #include <deque>
    
    template <class T>
    void print(const char* name, const std::deque<T>& c)
    {
      std::cout << name << " : {";
    
      for (const T& x : c) {
        std::cout << x << " ";
      }
    
      std::cout << "}" << std::endl;
    }
    
    int main()
    {
      std::deque<int> c1 = {1, 2, 3};
      std::deque<int> c2 = {4, 5, 6};
    
      std::swap(c1, c2);
    
      print("c1", c1);
      print("c2", c2);
    }
    

    出力

    c1 : {4 5 6 }
    c2 : {1 2 3 }
    

    参照