operator>> (<valarray>)
Right-shifts the bits for each element of a valarray a specified number of positions or by an element-wise amount specified by a second valarray.
template<class Type>
valarray<Type> operator>>(
const valarray<Type>& _Left,
const valarray<Type>& _Right
);
template<class Type>
valarray<Type> operator>>(
const valarray<Type>& _Left,
const Type& _Right
);
template<class Type>
valarray<Type> operator>>(
const Type& _Left,
const valarray<Type>& _Right
);
Parameters
_Left
The value to be shifted or the valarray whose elements are to be shifted._Right
The value indicating the amount of right shift or valarray whose elements indicate the element-wise amount of right shift.
Return Value
A valarray whose elements have been shifted right by the specified amount.
Remarks
Signed numbers have their signs preserved.
Example
// valarray_op_rs.cpp
// compile with: /EHsc
#include <valarray>
#include <iostream>
int main( )
{
using namespace std;
int i;
valarray<int> vaL ( 8 ), vaR ( 8 );
valarray<int> vaNE ( 8 );
for ( i = 0 ; i < 8 ; i += 2 )
vaL [ i ] = 64;
for ( i = 1 ; i < 8 ; i += 2 )
vaL [ i ] = -64;
for ( i = 0 ; i < 8 ; i++ )
vaR [ i ] = i;
cout << "The initial Left valarray is: ( ";
for ( i = 0 ; i < 8 ; i++ )
cout << vaL [ i ] << " ";
cout << ")." << endl;
cout << "The initial Right valarray is: ( ";
for ( i = 0 ; i < 8 ; i++ )
cout << vaR [ i ] << " ";
cout << ")." << endl;
vaNE = ( vaL >> vaR );
cout << "The element-by-element result of "
<< "the right shift is the\n valarray: ( ";
for ( i = 0 ; i < 8 ; i++ )
cout << vaNE [ i ] << " ";
cout << ")." << endl;
}
The initial Left valarray is: ( 64 -64 64 -64 64 -64 64 -64 ). The initial Right valarray is: ( 0 1 2 3 4 5 6 7 ). The element-by-element result of the right shift is the valarray: ( 64 -32 16 -8 4 -2 1 -1 ).
Requirements
Header: <valarray>
Namespace: std