Udostępnij za pośrednictwem


slice::size

Finds the number of elements in a slice of a valarray.

size_t size( ) const;

Return Value

The number of elements in a slice of a valarray.

Example

// slice_size.cpp
// compile with: /EHsc
#include <valarray>
#include <iostream>

int main( )
{
   using namespace std;
   int i;
   size_t sizeVA, sizeVAR;

   valarray<int> va ( 20 ), vaResult;
   for ( i = 0 ; i < 20 ; i += 1 )
      va [ i ] =  i+1;

   cout << "The operand valarray va is:\n ( ";
      for ( i = 0 ; i < 20 ; i++ )
         cout << va [ i ] << " ";
   cout << ")." << endl;

   sizeVA = va.size ( );
   cout << "The size of the valarray is: "
        << sizeVA << "." << endl << endl;

   slice vaSlice ( 3 , 6 , 3 );
   vaResult = va [ vaSlice ];

   cout << "The slice of valarray va is vaResult = "
        << "va[slice( 3, 6, 3)] =\n ( ";
      for ( i = 0 ; i < 6 ; i++ )
         cout << vaResult [ i ] << " ";
   cout << ")." << endl;

   sizeVAR = vaSlice.size ( );
   cout << "The size of slice vaSlice is: "
        << sizeVAR << "." << endl;
}

The operand valarray va is: ( 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 ). The size of the valarray is: 20. The slice of valarray va is vaResult = va[slice( 3, 6, 3)] = ( 4 7 10 13 16 19 ). The size of slice vaSlice is: 6.

Requirements

Header: <valarray>

Namespace: std

See Also

Reference

slice Class

Other Resources

slice Members