cshift

Syntax:

    #include <valarray>
    valarray cshift( size_t num ) const;

The cshift() function creates a new valarray, cyclically shifted left by num elements. Elements shifted beyond the leftmost end are wrapped to the rightmost end of the valarray.

This function does not affect the previous contents of the valarray.

The following code will cyclicly shift the elements left by 2 places:

   #include <valarray>
   #include <iostream>
 
   std::valarray<int> v1 = {1,2,3,4,5};
   for (size_t i=0; i<v1.size(); ++i) std::cout << v1[i];
   std::cout << std::endl;
 
   std::valarray<int> v2 = v1.cshift(2);
   for (size_t i=0; i<v2.size(); ++i) std::cout << v2[i];
   std::cout << std::endl;

Will produce this output:

   12345
   34512