shift [C++ Reference]
Keywords: valarray,shift
Date: 2009-06-24T14:38:20-0700

[[shift]]
C++ Reference
Translations of this page?:

- en
- br-pt
- cn
- cz
- de
- es
- fr
- it
- jp
- nl
- pl
- ro
- ru
- sk
- tr
- tw

## 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

Edit this page • Old revisions
• • • Login • Index • Recent changes • RSS • cc •