bitset::reference
Klasy proxy, który zawiera odwołania do bitów zawartych w bitset, używany do dostępu i manipulować pojedynczymi bitami jako klasa pomocy dla operator[] z klasy bitset.
class reference {
friend class bitset<N>;
public:
reference& operator=(
bool _Val
);
reference& operator=(
const reference& _Bitref
);
bool operator~( ) const;
operator bool( ) const;
reference& flip( );
};
Parametry
_Val
Wartość obiektu typu bool przypisuje się nieco w bitset._Bitref
Odwołania w formularzu x [i -bitowy w pozycji i w bitset x.
Wartość zwracana
Odniesienie do bit w bitset określonej przez argument położenie pierwszego, drugiego i piąty funkcji Członkowskich odwołania klasy i true lub false, aby odzwierciedlić wartość zmodyfikowanego bit bitset dla funkcji elementów członkowskich trzeci i czwarty odwołania klasy.
Uwagi
Odwołania klasy istnieje tylko jako klasa pomocy dla bitset operator[].Klasa Członkowskie opisuje obiekt, który można uzyskać dostęp do poszczególnych bit w ciągu bitset.Niech b być obiektem typu bool, x i y obiekty typu bitset <n>, i i i j prawidłowe pozycje w ramach takiego obiektu.Notacja x [i bit w pozycji odniesienia i w bitset x.W kolejności, funkcje składowe klasy odniesienia zawierają następujące operacje:
Operacja |
Definicja |
---|---|
xi= b |
Sklepy bool wartość b w pozycji bitu i w bitset x. |
xi= yj |
Przechowuje wartość bit yjw pozycji bitu i w bitset x. |
b = ~xi |
Przechowuje wartość przerzucane bit xi wboolb. |
b = xi |
Stores the value of the bit xi inboolb. |
xi.flip( ) |
Przechowuje wartość przerzucane bit xiWstecz w pozycji bitu i w x. |
Przykład
// 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 << ".";
}
Wymagania
Nagłówek: <bitset>
Obszar nazw: std