Translations of this page?:

shift

Syntax:

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

The shift() function creates a new valarray, shifted left by num elements.

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

The following code will 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.shift(2);
   for (size_t i=0; i<v2.size(); ++i) std::cout << v2[i];
   std::cout << std::endl;

Will produce this output:

   12345
   345
 
• • • IndexRecent changesRSScc