It returns a copy of the valarray object with its elements rotated left n spaces (or right if n is negative).
DeclarationFollowing is the declaration for std::valarray::cshift function.
valarray cshift (int n) const;C++11
valarray cshift (int n) const;Parameters
n − It is used to find number of elements to rotate.
Return ValueIt returns a copy of the valarray object with its elements rotated left n spaces.
ExceptionsBasic guarantee − if any operation performed on the elements throws an exception.
Data racesAll elements effectively copied are accessed.
ExampleIn below example explains about std::valarray::cshift function.
#include <iostream> #include <cstddef> #include <valarray> int main () { int init[]={0,10,20,30,40}; std::valarray<int> myvalarray (init,5); myvalarray = myvalarray.cshift(2); myvalarray = myvalarray.cshift(-1); std::cout << "valarray 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 −
valarray contains: 10 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