title: C++11 standard conformant bitmasks using enum class
body: <p>Can you implement standard conformant (as described in 17.5.2.1.3 of the n3242 draft) type safe bitmasks using enum class? The way I read it, a type T is a bitmask if it supports the |,&amp;,^,~,|=,&amp;= and ^= operators and further you can do if(l&amp;r) where l and r are of type T. Missing from the list are the operator != and == and to allow sorting one probably also wants to overload &lt;.</p>
  
  <p>Getting the operators to works is just annoying boilerplate code but I do not see how to do if(l&amp;r). At least the following does not compile with GCC (besides being extremely dangerous as it allows an erroneous implicit conversion to int):</p>
  
  <pre><code>enum class Foo{
      operator bool(){
          return (unsigned)*this;
      }
  };
  </code></pre>
  
  <p>EDIT: I now know for certain that enum classes can not have members. The actual question how to do if(l&amp;r) remains though.</p>