title: Are enums the canonical way to implement bit flags?
body: <p>Currently I'm using enums to represent a state in a little game experiment. I declare them like so:</p>
  
  <pre><code>namespace State {
    enum Value {
      MoveUp = 1 &lt;&lt; 0, // 00001 == 1
      MoveDown = 1 &lt;&lt; 1, // 00010 == 2
      MoveLeft = 1 &lt;&lt; 2, // 00100 == 4
      MoveRight = 1 &lt;&lt; 3, // 01000 == 8
      Still = 1 &lt;&lt; 4, // 10000 == 16
      Jump = 1 &lt;&lt; 5
    };
  }
  </code></pre>
  
  <p>So that I can use them this way:</p>
  
  <pre><code>State::Value state = State::Value(0);
  state = State::Value(state | State::MoveUp);
  if (mState &amp; State::MoveUp)
    movement.y -= mPlayerSpeed;
  </code></pre>
  
  <p>But I'm wondering if this is the right way to implement bit flags. Isn't there a special container for bit flags? I heard about <code>std::bitset</code>, is it what I should use? Do you know something more efficient?<br>
  <strong>Am I doing it right?</strong></p>
  
  <p><hr>
  I forgot to point out I was overloading the basic operators of my enum:</p>
  
  <pre><code>inline State::Value operator|(State::Value a, State::Value b)
  { return static_cast&lt;State::Value&gt;(static_cast&lt;int&gt;(a) | static_cast&lt;int&gt;(b)); }
  
  inline State::Value operator&amp;(State::Value a, State::Value b)
  { return static_cast&lt;State::Value&gt;(static_cast&lt;int&gt;(a) &amp; static_cast&lt;int&gt;(b)); }
  
  
  inline State::Value&amp; operator|=(State::Value&amp; a, State::Value b)
  { return (State::Value&amp;)((int&amp;)a |= (int)b); }
  </code></pre>
  
  <p>I had to use a C-style cast for the <code>|=</code>, it didn't work with a <code>static_cast</code> - any idea why?</p>