共用方式為


operator&

取得項目型別之間的一個 valarray 和指定值的位元 AND 都同樣大小的 valarrays 之間的對應項目。

template<class Type>
   valarray<Type> operator&(
      const valarray<Type>& _Left,
      const valarray<Type>& _Right
   );
template<class Type>
   valarray<Type> operator&(
      const valarray<Type>& _Left,
      const Type& _Right
   );
template<class Type>
   valarray<Type> operator&(
      const Type& _Left,
      const valarray<Type>& _Right
   );

參數

  • _Left
    個別項目將位元結合 AND 或項目型別的某個值與每個項目組合的位元的 valarray 的第一個 valarrays。

  • _Right
    個別項目將位元結合 AND 或項目型別的某個值與每個項目組合的位元的 valarray 的第二個 valarrays。

傳回值

項目是 _Left 和 _Right.位元 AND 運算項目組合的 valarray

備註

位元運算只能用於操作位元在 char 和 int 資料型別和變數而 floatdoublelong doublevoid,bool ,或其他更複雜的資料型別。

位元 AND 會執行資訊清單和邏輯 AND ,但適用於個別位元的層級上的資料型別。 運算子&& 在項目層級上套用,計算為任何非零值為 true,,而結果是 valarray 布林值。 除了 0 或 1 以外,位元 AND operator&,相反,可能會導致 valarray 值,根據資料位元運算的結果。

範例

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

int main( )
{
   using namespace std;
   int i;

   valarray<int> vaL ( 10 ), vaR ( 10 );
   valarray<int> vaBWA ( 10 );
   for ( i = 0 ; i < 10 ; i += 2 )
      vaL [ i ] =  0;
   for ( i = 1 ; i < 10 ; i += 2 )
      vaL [ i ] =  i+1;
   for ( i = 0 ; i < 10 ; i++ )
      vaR [ i ] =  i;
   
   cout << "The initial Left valarray is:  ( ";
      for ( i = 0 ; i < 10 ; i++ )
         cout << vaL [ i ] << " ";
   cout << ")." << endl;

   cout << "The initial Right valarray is: ( ";
      for ( i = 0 ; i < 10 ; i++ )
         cout << vaR [ i ] << " ";
   cout << ")." << endl;

   vaBWA = ( vaL & vaR );
   cout << "The element-by-element result of "
        << "the bitwise operator & is the\n valarray: ( ";
      for ( i = 0 ; i < 10 ; i++ )
         cout << vaBWA [ i ] << " ";
   cout << ")." << endl;
}
  

需求

標頭: <valarray>

命名空間: std