Condividi tramite


valarray::shift

Scorrere tutti gli elementi in un valarray da un determinato numero di posizioni.

valarray<Type> shift(
   int _Count
) const;

Parametri

  • _Count
    Il numero di posizioni gli elementi è possibile scorrere in avanti.

Valore restituito

Un nuovo valarray in cui tutti gli elementi sono stati spostati percorsi _Count all'inizio del valarray, sinistra rispetto alle relative posizioni l'operando valarray.

Note

Un valore positivo _Count scorre gli elementi lasciati i punti _Count, con fill zero.

Un valore negativo _Count scorre i punti della _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

intestazione: <valarray>

Spazio dei nomi: deviazione standard

Vedere anche

Riferimenti

valarray Class