共用方式為


mask_array Class

支援物件是父 valarrays 的子集,指定具有布林運算式,它可以提供在子集之間的操作的內部,其他的樣板類別範圍。

template<class Type>
   class mask_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<bool>ba 一起儲存在物件中 valarray<Type>va 的參考,因此,描述項目序列 valarray<Type> 物件中選取的物件。

您可以撰寫表單 [] ba VA的運算式只 mask_array<Type> 建構物件。 mask_array 類別的成員函式接著會與對應的函式簽章定義的 valarray<Type>,但是有一點例外,就是選取的項目序列只會受到影響。

這個序列包含最多 ba.size 項目。 項目 包含時,才會 baJ[] 則為 true。 因此,,儘管有 ba,真正的項目具有在序列中許多項目。 如果 I 是最低 true 之項目的索引。 ba的,則 va[]I是項目零選項的序列。

範例:

// mask_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;

   // Use masked subsets to assign a value of 10
   // to all elements grrater than 3 in value
   va [va > 3 ] = 10;
   cout << "The modified operand valarray is:  ( ";
      for ( i = 0 ; i < 10 ; i++ )
         cout << va [ i ] << " ";
   cout << ")." << endl;
}

yxbhx0s5.collapse_all(zh-tw,VS.110).gifOutput

The initial operand valarray is:  ( 0 -1 2 -1 4 -1 6 -1 8 -1 ).
The modified operand valarray is:  ( 0 -1 2 -1 10 -1 10 -1 10 -1 ).

需求

標題: <valarray>

命名空間: std

請參閱

參考

在標準 C++ 程式庫中的執行緒安全