bitset::reference

Una clase de proxy que proporciona referencias a los bits contenidos en una bitset que se utiliza para tener acceso y manipular los bits individuales como una clase auxiliar para operator[] de bitset de la clase.

class reference {
   friend class bitset<N>;
   public:
      reference& operator=(
         bool _Val
      );
      reference& operator=(
         const reference& _Bitref
      );
      bool operator~( ) const;
      operator bool( ) const;
      reference& flip( );
};

Parámetros

  • _Val
    El valor del objeto de bool tipo asignarlos a un bit en un bitset.

  • _Bitref
    Una referencia de formulario x [i] al bit en la posición i en el bitset x.

Valor devuelto

Una referencia al bit del bitset especificado por el argumento colocar para el primer, segundo, y las quintas funciones miembro de referencia de la clase, y TRUE o Falso, para reflejar el valor de bit modificado en el bitset para la tercera y la cuarta funciones miembro de referencia de la clase.

Comentarios

La referencia de la clase solo existe como clase auxiliar para el bitset operator[].La clase miembro describe un objeto que puede tener acceso a un bit individual dentro de un bitset.Deje la b ser un objeto de boolcon tipo, de x y objetos de la yla Ntipo**>**de bitset<, y las posiciones válidas de i y j dentro de ese objeto.la notación x [i] hace referencia el bit en la posición i en el bitset *x.*Las funciones miembro de referencia de la clase proporcionan, en orden, las operaciones siguientes:

Operación

Definición

x[i] = b

Almacena b del valor de bool en la posición de bit i en el bitset x.

x[i] = y[j]

Almacena el valor de yde bits [j] en la posición de bit i en el bitset x.

b = ~x [i]

Almacena el valor movido volteado de bits x[i] ende bool.

b = x[i]

Almacena el valor de bit x[i] ende bool.

x[i].flip()

Almacena el valor movido volteado posteriores de bits x[i] en la posición de bit i en x- .

Ejemplo

// bitset_reference.cpp
// compile with: /EHsc
#include <bitset>
#include <iostream>

int main( )
{
   using namespace std;

   bitset<5> b1 ( 2 );
   bitset<5> b2 ( 6 );
   cout << "The initialized bitset<5> b1( 2 ) is: ( "<< b1 << " )."
        << endl;
   cout << "The initialized bitset<5> b2( 6 ) is: ( "<< b2 << " )."
        << endl;

   // Example of x [i] = b storing bool b at bit position i
   // in bitset x
   b1[ 0 ] = true;
   cout << "The bitset<5> b1 with the bit at position 0 set to 1"
        << " is: ( "<< b1 << " )" << endl;
   
   // Example of x [i] = y [j] storing the bool value of the
   // bit at position j in bitset y at bit position i in bitset x
   b2 [4] = b1 [0];      // b1 [0] = true
   cout << "The bitset<5> b2 with the bit at position 4 set to the "
        << "value\n of the bit at position 0 of the bit in "
        << "bitset<5> b1 is: ( "<<  b2  << " )" << endl;

   // Example of b = ~x [i] flipping the value of the bit at
   // position i of bitset x and storing the value in an 
   // object b of type bool
   bool b = ~b2 [4];      // b2 [4] = false
   if ( b )
      cout << "The value of the object b = ~b2 [4] "
           << "of type bool is true." << endl;
   else
      cout << "The value of the object b = ~b2 [4] "
           << "of type bool is false." << endl;
   
   // Example of b = x [i] storing the value of the bit at
   // position i of bitset x in the object b of type bool
   b = b2 [4];
   if ( b )
      cout << "The value of the object b = b2 [4] "
           << "of type bool is true." << endl;
   else
      cout << "The value of the object b = b2 [4] "
           << "of type bool is false." << endl;

   // Example of x [i] . flip ( ) toggling the value of the bit at
   // position i of bitset x
   cout << "Before flipping the value of the bit at position 4 in "
        << "bitset b2,\n it is ( "<<  b2  << " )." << endl;
   b2 [4].flip( );
   cout << "After flipping the value of the bit at position 4 in "
        << "bitset b2,\n it becomes ( "<<  b2  << " )." << endl;
   bool c;
   c = b2 [4].flip( );
   cout << "After a second toggle, the value of the position 4"
        << " bit in b2 is now: " << c << ".";
}
  
  
  
  
  
  
  

Requisitos

encabezado: <bitset>

espacio de nombres: std

Vea también

Referencia

bitset Class

Seguridad para subprocesos de la biblioteca estándar de C++