public member function
<valarray>
std::valarray::cshift
valarray cshift (int n) const;
Circularly shift elements
The valarray returned has the same length as *this.
By cyclically shifting (rotating) an array, the I-th element in the resulting valarray corresponds to the element with position (I+n)%size() in the original valarray.
Unlike valarray::shift, the valarray returned by cshift does not initialize new elements with their default constructor to fill the last n elements in *this (or the first -n elements if n is negative). Instead, it uses the first (or last) elements of *this.
Parameters
- n
- Number of elements to rotate. If positive, it is rotated left. If negative, it is rotated right.
Return value
A new valarray object with the elements of*this rotated n spaces left.Example
|
|
Output:
myvalarray contains: 20 30 40 50 10
Complexity
Depends on library implementation.Iterator validity
No changes: Valid iterators, references and sub-arrays of the source valarray keep their validity.Data races
Both the valarray and its elements are accessed.Exception safety
If the function implementation constructs or assigns to elements, and any such operation throws an exception, it causes undefined behavior.If the function needs to allocate internal storage and fails, it may throw an exception (such as bad_alloc), although this is not mandated.
See also
- valarray::shift
- Shift elements (public member function)
- valarray operators
- Valarray operators (function)