indirect_array Class
작업 간에 배열의 하위 집합을 제공 하 여 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
}
설명
클래스 개체에 대 한 참조를 저장 하는 개체에 설명 합니다. va 클래스의 valarray<Type>, 개체와 함께 xa 클래스의 valarray <size_t>, 설명 하는 시퀀스의 요소를 선택 하는 valarray <Type> 개체.
구성 된 indirect_array <Type> 개체 형식의 식을 작성 하 여 va [xa.해당 함수 시그니처를 정의 하는 것 처럼 indirect_array 클래스의 멤버 함수는 다음 동작 valarray <Type>, 선택한 요소 시퀀스를 영향을 받는 경우를 제외 하 고.
시퀀스 구성 xa.크기 요소는 요소 I 인덱스 됩니다 xaI 내 va.
예를 들면 와 같은 형식입니다.
// 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;
}
Output
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