std::swap(std::valarray)
From cppreference.com
| ヘッダ <valarray> で定義 |
||
| template< class T > void swap( std::valarray<T>& lhs, std::valarray<T>& rhs ) noexcept; |
(C++11以降) | |
std::swap アルゴリズムの std::valarray 用特殊化。 lhs と rhs の内容を交換します。 lhs.swap(rhs) を呼び出します。
目次 |
[編集] パラメータ
| lhs, rhs | - | 交換する valarray の内容 |
[編集] 戻り値
(なし)
[編集] 計算量
定数。
[編集] 例
このコードを実行
#include <iostream> #include <valarray> void print(auto rem, const std::valarray<int>& v) { std::cout << rem << '{'; for (char sep[]{0, ' ', 0}; auto elem : v) std::cout << sep << elem, *sep = ','; std::cout << "}\n"; } int main() { std::valarray x{3, 1, 4, 1, 5}; std::valarray y{2, 7, 1, 8}; print("Before swap:\n" "x: ", x); print("y: ", y); std::swap(x, y); print("After swap:\n" "x: ", x); print("y: ", y); }
出力
Before swap:
x: {3, 1, 4, 1, 5}
y: {2, 7, 1, 8}
After swap:
x: {2, 7, 1, 8}
y: {3, 1, 4, 1, 5}[編集] 関連項目
| 別の valarray との交換 (public member function) |