サブセットの配列間の操作によって valarrays 実行するオブジェクトのサブセットをサポートする内部の許可、テンプレート クラスは valarray 親のインデックスのサブセットを指定して定義されています。
template<class Type>
class indirect_array {
public:
typedef Type value_type;
void operator=(
const valarray<Type>& x
) const;
void operator=(
const Type& x
) const;
void operator*=(
const valarray<Type>& x
) const;
void operator/=(
const valarray<Type>& x
) const;
void operator%=(
const valarray<Type>& x
) const;
void operator+=(
const valarray<Type>& x
) const;
void operator-=(
const valarray<Type>& x
) const;
void operator^=(
const valarray<Type>& x
) const;
void operator&=(
const valarray<Type>& x
) const;
void operator|=(
const valarray<Type>& x
) const;
void operator<<=(
const valarray<Type>& x
) const;
void operator>>=(
const valarray<Type>& x
) const;
// The rest is private or implementation defined
}
解説
クラスは、クラス **valarray<size_t>のオブジェクト valarray<Type> のオブジェクトから選択する要素のシーケンスを記述できます xa とともにオブジェクトを格納 valarrayクラス<Type>**のオブジェクトへの参照 [VA]、ついて説明します。
フォーム **va[xa]**の式を記述することによってのみ indirect_array<Type> オブジェクトを構築します。indirect_array **valarray<Type>**に対して定義されているクラスのメンバー関数では、対応する関数定義のように、が、選択した要素のシーケンスのみ影響します。
シーケンスは、要素 I が **[VA]**内のインデックス xa[入力]Iする xa.サイズ の要素で構成されます。
例:
// indirect_array.cpp
// compile with: /EHsc
#include <valarray>
#include <iostream>
int main( )
{
using namespace std;
int i;
valarray<int> va ( 10 );
for ( i = 0 ; i < 10 ; i += 2 )
va [ i ] = i;
for ( i = 1 ; i < 10 ; i += 2 )
va [ i ] = -1;
cout << "The initial operand valarray is: ( ";
for ( i = 0 ; i < 10 ; i++ )
cout << va [ i ] << " ";
cout << ")." << endl;
// Select 2nd, 4th & 6th elements
// and assign a value of 10 to them
valarray<size_t> indx ( 3 );
indx [0] = 2;
indx [1] = 4;
indx [2] = 6;
va[indx] = 10;
cout << "The modified operand valarray is: ( ";
for (i = 0 ; i < 10 ; i++ )
cout << va [ i ] << " ";
cout << ")." << endl;
}
出力
The initial operand valarray is: ( 0 -1 2 -1 4 -1 6 -1 8 -1 ).
The modified operand valarray is: ( 0 -1 10 -1 10 -1 10 -1 8 -1 ).
必要条件
ヘッダー: <valarray>
名前空間: std