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

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

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

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

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