title: C++ enum flags vs bitset
body: <p>What are pros/cons of usage bitsets over enum flags?</p>
  
  <pre><code>namespace Flag {
      enum State {
          Read   = 1 &lt;&lt; 0,
          Write  = 1 &lt;&lt; 1,
          Binary = 1 &lt;&lt; 2,
      };
  }
  
  namespace Plain {
      enum State {
          Read,
          Write,
          Binary,
          Count
      };
  }
  
  int main()
  {
      {
          unsigned int state = Flag::Read | Flag::Binary;
          std::cout &lt;&lt; state &lt;&lt; std::endl;
  
          state |= Flag::Write;
          state &amp;= ~(Flag::Read | Flag::Binary);
          std::cout &lt;&lt; state &lt;&lt; std::endl;
      } {
          std::bitset&lt;Plain::Count&gt; state;
          state.set(Plain::Read);
          state.set(Plain::Binary);
          std::cout &lt;&lt; state.to_ulong() &lt;&lt; std::endl;
  
          state.flip();
          std::cout &lt;&lt; state.to_ulong() &lt;&lt; std::endl;
      }
  
      return 0;
  }
  </code></pre>
  
  <p>As I can see so far, bitsets have more convinient set/clear/flip functions to deal with, but enum-flags usage is a more wide-spreaded approach.</p>
  
  <p>What are possible downsides of bitsets and what and when should I use in my daily code?</p>