Namensräume
Varianten
Aktionen

std::swap(std::valarray)

Von cppreference.com
< cpp‎ | numeric‎ | valarray
 
 
 
 
Definiert in der Header-Datei <valarray>
template< class T >
void swap( std::valarray<T>& lhs, std::valarray<T>& rhs ) noexcept;
(seit C++11)

Spezialisiert den Algorithmus std::swap für std::valarray. Tauscht die Inhalte von lhs und rhs. Ruft lhs.swap(rhs) auf.

Inhalt

[edit] Parameter

lhs, rhs - valarrays, deren Inhalte getauscht werden sollen

[edit] Rückgabewert

(keine)

[edit] Komplexität

Konstant.

[edit] Beispiel

#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);
}

Ausgabe

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}

[edit] Siehe auch

tauscht mit einem anderen valarray
(öffentliche Member-Funktion) [edit]