- stack[meta header]
- std[meta namespace]
- stack[meta class]
- function[meta id-type]
- cpp11[meta cpp]
void swap(stack& s) noexcept(noexcept(swap(c, s.c)));他の stack オブジェクトと値を入れ替える。
swap(c, s.c)
なし
swap(c, s.c) が例外を投げない場合、この関数は決して例外を投げない。
#include <iostream>
#include <stack>
int main()
{
std::stack<int> x;
x.push(3);
x.push(1);
x.push(4);
std::stack<int> y;
y.push(2);
y.push(7);
y.push(1);
// 交換
x.swap(y);
// それぞれの要素を表示
std::cout << "x : ";
while (!x.empty()) {
std::cout << x.top() << " ";
x.pop();
}
std::cout << std::endl;
std::cout << "y : ";
while (!y.empty()) {
std::cout << y.top() << " ";
y.pop();
}
}- swap[color ff0000]
- push[link push.md]
- empty()[link empty.md]
- top()[link top.md]
- pop()[link pop.md]
x : 1 7 2
y : 4 1 3
void swap(stack& s) noexcept(noexcept(swap(c, s.c)))
{
using std::swap;
swap(c, s.c);
}- C++11
- Clang: ??
- GCC: ??
- GCC, C++11 mode: 4.7.0
- ICC: ??
- Visual C++: