A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.tutorialspoint.com/cpp_standard_library/cpp_valarray_swap_non.htm below:

C++ valarray Swap Non-Members

C++ valarray Library - Function swap Description

It exchanges the contents of *this and x.

Declaration

Following is the declaration for std::valarray::swap function.

template <class T>
   void swap (valarray<T>& x, valarray<T>& y) noexcept;
C++11
template <class T>
   void swap (valarray<T>& x, valarray<T>& y) noexcept;
Parameters

x,y − These are the another valarray objects of the same type.

Return Value

none

Exceptions

Basic guarantee − if any operation performed on the elements throws an exception.

Data races

All elements effectively copied are accessed.

Example

In below example explains about std::valarray::swap function.

#include <iostream>
#include <valarray>

int main () {
   std::valarray<int> foo {0,10,20,30};
   std::valarray<int> bar {100,200,300};

   foo.swap(bar);

   std::cout << "foo contains:";
   for (auto& x: foo) std::cout << ' ' << x;
   std::cout << '\n';

   std::cout << "bar contains:";
   for (auto& x: bar) std::cout << ' ' << x;
   std::cout << '\n';

   return 0;
}

Let us compile and run the above program, this will produce the following result −

foo contains: 100 200 300
bar contains: 0 10 20 30

valarray.htm


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4