title: How to check if enum value is valid?
body: <p>I am reading an <code>enum</code> value from a binary file and would like to check if the value is really part of the <code>enum</code> values. How can I do it?</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  enum Abc
  {
      A = 4,
      B = 8,
      C = 12
  };
  
  int main()
  {
      int v1 = 4;
      Abc v2 = static_cast&lt; Abc &gt;( v1 );
  
      switch ( v2 )
      {
          case A:
              std::cout&lt;&lt;"A"&lt;&lt;std::endl;
              break;
          case B:
              std::cout&lt;&lt;"B"&lt;&lt;std::endl;
              break;
          case C:
              std::cout&lt;&lt;"C"&lt;&lt;std::endl;
              break;
          default :
              std::cout&lt;&lt;"no match found"&lt;&lt;std::endl;
      }
  }
  </code></pre>
  
  <p>Do I have to use the <code>switch</code> operator or is there a better way?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I have enum values set and unfortunately I can not modify them. To make things worse, they are not continuous (their values goes 0, 75,76,80,85,90,95,100, etc.)</p>