title: How can I use an enum class in a boolean context?
body: <p>I have some generic code that works with flags specified using C++11 <code>enum class</code> types. At one step, I'd like to know if any of the bits in the flag are set. Currently, I'm using the code:</p>
  
  <pre><code>if (flags != static_cast&lt;E&gt;(0)) // Works, but ugly.
  </code></pre>
  
  <p>I could also force users to specify a particular name for an all-zero field, which is more readable but imposes my naming conventions on anyone using it:</p>
  
  <pre><code>if (flags != E::none) // Works, if you manually define none = 0.
  </code></pre>
  
  <p>But neither of these reads as nicely as the traditional:</p>
  
  <pre><code>if (flags) // Doesn't work with class enums.
  </code></pre>
  
  <p>Is it possible to specify a custom function to evaluate a class enum in a boolean context?</p>