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_shift.htm below:

C++ valarray Shift Function

C++ valarray Library - Function shift Description

It returns a copy of the valarray object with its elements shifted left n spaces (or right if n is negative).

Declaration

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

valarray shift (int n) const;
C++11
valarray shift (int n) const;
Parameters

n − It is contains the information about number of elements to shift.

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::shift function.

#include <iostream>
#include <cstddef>
#include <valarray>

int main () {
   int init[]={0,10,20,30,40};

   std::valarray<int> myvalarray (init,5);
   myvalarray = myvalarray.shift(2);
   myvalarray = myvalarray.shift(-1);

   std::cout << "myvalarray contains:";
   for (std::size_t n=0; n<myvalarray.size(); n++)
      std::cout << ' ' << myvalarray[n];
   std::cout << '\n';

   return 0;
}

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

myvalarray contains: 0 20 30 40 0

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