void swap(deque& other);
void swap(deque& x) noexcept(allocator_traits<Allocator>::is_always_equal::value); // C++17
概要
他のdeque
オブジェクトとデータを入れ替える。
効果
*this
とother
のデータを交換する。
戻り値
なし
計算量
定数時間
備考
swapされるコンテナの要素を指す参照、ポインタ、イテレータを無効化しない。
例
#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};
c1.swap(c2);
print("c1", c1);
print("c2", c2);
}
出力
c1 : {4 5 6 }
c2 : {1 2 3 }
参照
- N4258 Cleaning-up noexcept in the Library, Rev 3
noexcept
追加の経緯となる提案文書