valarray::shift
Scorre tutti gli elementi in un valarray da un dato numero di posizioni.
valarray<Type> shift(
int _Count
) const;
Parametri
- _Count
Il numero di posizioni gli elementi è possibile scorrere avanti.
Valore restituito
Un nuovo valarray in cui tutti gli elementi sono stati spostati posizioni di _Count all'inizio del valarray, sinistra rispetto alle relative posizioni nell'operando valarray.
Note
Un valore positivo di _Count scorre gli elementi lasciati i punti di _Count, with padding zero.
Un valore negativo di _Count scorre i margini destro punti di _Count di elementi, con fill zero.
Esempio
// valarray_shift.cpp
// compile with: /EHsc
#include <valarray>
#include <iostream>
int main( )
{
using namespace std;
int i;
valarray<int> va1 ( 10 ), va2 ( 10 );
for ( i = 0 ; i < 10 ; i += 1 )
va1 [ i ] = i;
for ( i = 0 ; i < 10 ; i += 1 )
va2 [ i ] = 10 - i;
cout << "The operand valarray va1(10) is: ( ";
for ( i = 0 ; i < 10 ; i++ )
cout << va1 [ i ] << " ";
cout << ")." << endl;
// A positive parameter shifts elements left
va1 = va1.shift ( 4 );
cout << "The shifted valarray va1 is: va1.shift (4) = ( ";
for ( i = 0 ; i < 10 ; i++ )
cout << va1 [ i ] << " ";
cout << ")." << endl;
cout << "The operand valarray va2(10) is: ( ";
for ( i = 0 ; i < 10 ; i++ )
cout << va2 [ i ] << " ";
cout << ")." << endl;
// A negative parameter shifts elements right
va2 = va2.shift ( - 4 );
cout << "The shifted valarray va2 is: va2.shift (-4) = ( ";
for ( i = 0 ; i < 10 ; i++ )
cout << va2 [ i ] << " ";
cout << ")." << endl;
}
Requisiti
Header: <valarray>
Spazio dei nomi: std