title: Combine enums c++
body: <p>In my project, I have several enum declarations alike this one;</p>
  
  <pre><code>enum Comparison
  {
      LT,     // "&lt;"
      GT,     // "&gt;"
      EQ,     // "=="
      LTEQ,   // "&lt;="
      GTEQ,   // "&gt;="
      NEQ     // "!="
  };
  enum Arithmetic
  {
      ADD,    // "+"
      SUB,    // "-"
      MUL,    // "*"
      DIV,    // "/"
      MOD,    // "%"
  };
  </code></pre>
  
  <p>And I'd like to combine several of these, into a single combined enum, such that;</p>
  
  <ul>
  <li>All elements (from the sub-enums) are present in the combined enum.</li>
  <li>All elements have a unique value (obviously).</li>
  <li>All elements have consistent value in the combined enum, and the original.</li>
  </ul>
  
  <p>Like this:</p>
  
  <pre><code>enum Comparison
  {
      LT,     // "&lt;"
      GT,     // "&gt;"
      EQ,     // "=="
      LTEQ,   // "&lt;="
      GTEQ,   // "&gt;="
      NEQ     // "!="
  
      ADD,    // "+"
      SUB,    // "-"
      MUL,    // "*"
      DIV,    // "/"
      MOD,    // "%"
  };
  </code></pre>
  
  <p>Also what I'd like to be able to do, is to 'cast' the combined enum, to one of the original ones, given the value in the combined enum only (should be trivial assuming the values are consistent).</p>
  
  <p>An alternative to enum, is a class based solution, where the classes implement the <code>operator int()</code> operator.</p>
  
  <p>Note; I do believe the <code>operator int()</code> is somehow the way to go.</p>