From cppreference.com
template<classT>voidswap(std::valarray<T>&lhs,std::valarray<T>&rhs)noexcept;(since C++11)Specializes the
algorithm for
. Swaps the contents of lhs and rhs. Calls lhs.swap(rhs).
Parameters
lhs, rhs - valarrays whose contents to swap Return value
(none)
Complexity
Constant.
Example
Run this code
#include<iostream>#include<valarray>voidprint(autorem,conststd::valarray<int>&v){std::cout<<rem<<'{';for(charsep[]{0,' ',0};autoelem:v)std::cout<<sep<<elem,*sep=',';std::cout<<"}\n";}intmain(){std::valarrayx{3,1,4,1,5};std::valarrayy{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);}Output:
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} See also
swaps with another valarray
(public member function)