gslice::size
查找数组值指定元素个数泛型切片valarray。
valarray<size_t> size( ) const;
返回值
valarray指定元素数。每段一般切片valarray。
备注
成员函数返回切片的存储的长度。
示例
// gslice_size.cpp
// compile with: /EHsc
#include <valarray>
#include <iostream>
int main( )
{
using namespace std;
int i;
size_t sizeVA;
valarray<int> va ( 20 ), vaResult;
for ( i = 0 ; i < 20 ; i+=1 )
va [ i ] = i;
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;
valarray<size_t> Len ( 2 ), Stride ( 2 );
Len [0] = 4;
Len [1] = 4;
Stride [0] = 7;
Stride [1] = 4;
gslice vaGSlice ( 0, Len, Stride );
vaResult = va [ vaGSlice ];
const valarray <size_t> sizeGS = vaGSlice.size ( );
cout << "The valarray for vaGSlice is vaResult:"
<< "\n va[vaGSlice] = ( ";
for ( i = 0 ; i < 8 ; i++ )
cout << vaResult [ i ] << " ";
cout << ")." << endl;
cout << "The size of vaResult is:"
<< "\n vaGSlice.size ( ) = ( ";
for ( i = 0 ; i < 2 ; i++ )
cout << sizeGS[ i ] << " ";
cout << ")." << endl;
}
要求
标头: <valarray>
命名空间: std