title: Implementation of operators for enum class
body: <p>Following the discussion in question <a href="https://stackoverflow.com/questions/15450914/incrementation-and-decrementation-of-enum-class">Incrementation and decrementation of “enum class”</a>, I'd like to ask about the possible implementation of arithmetic operators for <code>enum class</code> types. </p>
  
  <p>Example from the original question:</p>
  
  <pre><code>enum class Colors { Black, Blue, White, END_OF_LIST };
  
  // Special behavior for ++Colors
  Colors&amp; operator++( Colors &amp;c ) {
    c = static_cast&lt;Colors&gt;( static_cast&lt;int&gt;(c) + 1 );
    if ( c == Colors::END_OF_LIST )
      c = Colors::Black;
    return c;
  }
  </code></pre>
  
  <p>Is there a way to implement arithmetic operators without casting to a type with already defined operators? I can't think of any, but casting bothers me. Casts are usually indication of something wrong and there has to be a very good reason for their usage. I would expect the language to allow implementation of an operator to be achievable without forcing to a specific type.</p>
  
  <p><strong>Update Dec 2018</strong>:
  One of the papers towards C++17 seems to address this at least partially by allowing conversions between enum class variable and the underlying type: <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0138r2.pdf" rel="noreferrer">http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0138r2.pdf</a></p>