title: Simplest method for iterating through contiguous enum values in C++
body: <p>What is the preferred <em>simple</em> method for iterating through an enum with contiguous values in C++? I found previous SO questions on this subject which involved creating custom <code>operator++</code> etc, but this seems like overkill. So far the best I have come up with is:</p>
  
  <pre><code>enum {
     FOO,
     BAR,
     BLECH,
     NUM_ENUMS
  } MyEnum;
  
  //for (MyEnum m = FOO; m &lt; NUM_ENUMS; ++m)             // compile error
  //    ...
  
  //for (MyEnum m = FOO; m &lt; NUM_ENUMS; m = m + 1)       // compile error
  //    ...
  
  for (MyEnum m = FOO; m &lt; NUM_ENUMS; m = MyEnum(m + 1)) // OK ?
      ...
  </code></pre>
  
  <p>Is this reasonable from a coding style perspective and is it likely to generate warnings (<code>g++ -Wall ...</code> seems happy with this) ?</p>