Namespaces
Variants

std:: swap (std::valarray)

From cppreference.net
헤더에 정의됨 <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)