operator^
Obtém OR exclusivo bit a bit) (XORentre os elementos correspondentes de dois valarrays igualmente feito sob medida ou um valor entre valarray e do tipo do elemento especificado.
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
);
Parâmetros
_Left
O primeiro dos dois valarrays cujos elementos respectivos são combinados com XOR bit a bit ou um valor do tipo do elemento especificado para ser bit a bit combinado com cada elemento de um valarray._Right
O segundo de dois valarrays cujos elementos respectivos são combinados com XOR bit a bit ou um valor do tipo do elemento especificado para ser bit a bit combinado com cada elemento de um valarray.
Valor de retorno
Um valarray cujos elementos sejam elemento pela combinação da operação bit a bit de XOR de _Left e de _Right.
Comentários
Uma operação bit a bit só pode ser usado para manipular bit em char e tipos de dados e variantes de int e não em float, em double, em long double, em void bool ou em outro, os tipos de dados mais complexos.
OR exclusivo bit a bit (XOR) tem a seguinte semântica: Os bits dados b1e b2, b1XOR b2são exatamente de true se um bit for válido; false se ambos os bits forem false ou se ambos os bits forem true.
Exemplo
// valarray_op_xor.cpp
// compile with: /EHsc
#include <valarray>
#include <iostream>
int main( )
{
using namespace std;
int i;
valarray<int> vaL ( 10 ), vaR ( 10 );
valarray<int> vaLAA ( 10 );
for ( i = 0 ; i < 10 ; i += 2 )
vaL [ i ] = 1;
for ( i = 1 ; i < 10 ; i += 2 )
vaL [ i ] = 0;
for ( i = 0 ; i < 10 ; i += 3 )
vaR [ i ] = i;
for ( i = 1 ; i < 10 ; i += 3 )
vaR [ i ] = i-1;
for ( i = 2 ; i < 10 ; i += 3 )
vaR [ i ] = i-1;
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;
vaLAA = ( vaL ^ vaR );
cout << "The element-by-element result of "
<< "the bitwise XOR operator^ is the\n valarray: ( ";
for ( i = 0 ; i < 10 ; i++ )
cout << vaLAA [ i ] << " ";
cout << ")." << endl;
}
Requisitos
Cabeçalho: <valarray>
Namespace: std