bitset::reference

提供的代理选件类对使用访问的bitset包含的位和操作的单个位作为选件类bitset operator[] 的帮助器选件类。

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

参数

  • _Val
    类型的分配的 bool 对象的值分配给bitset的位。

  • _Bitref
    窗体 x [] i的 引用位的位置在 在bitset X。

返回值

对位的引用将参数位置指定的bitset为第一,秒和选件类的第五个成员函数引用,并且,truefalse,反映已修改的位的值。bitset的选件类的第三个和第四个成员函数的引用。

备注

选件类的引用仅作为bitset的 **operator[]**帮助器选件类。成员选件类描述可以在bitset内单独的位的对象。允许 b 是类型 **bitset<N>**和在此类对象中的 ij 有效位置类型 bool,xy 对象对象。表示法 x [] i 引用位在位置 在bitset *X。*选件类的成员函数引用按顺序提供,以下操作:

操作

定义

x[]i= b

存储 bool 值 b 在数位位置 在bitset X。

xi= [] []jy

存储位 y[]j的值在数位位置 在bitset X。

b ~xi= []

x[i] 存储位 boolb翻转的值。

bxi= []

x[i] 存储位 boolb值。

xi[]。flip()

存储位 x[]i返回的翻转的值在数位位置 x。

示例

// 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 << ".";
}
  
  
  
  
  
  
  

要求

标头: <bitset>

命名空间: std

请参见

参考

bitset Class

线程安全性对标准C++库中