title: Safety of calling C++ functions with enum created using static_cast
body: <p>I have been using enumerations for function input parameters, but I have noticed that this may be very dangerous.</p>
  <p>For example:</p>
  <pre class="lang-cpp prettyprint-override"><code>enum class MYENUM {
      X1 = 0, X2
  };
  
  std::map&lt;MYENUM, int&gt; mymap;
  //init mymap here with known enum values of X1 and X2
  
  
  int MyFunc(const MYENUM&amp; input) {
      return mymap.at(input);
  }
  
  int main() {
      MyFunc(static_cast&lt;MYENUM&gt;(10000));
  }
  </code></pre>
  <p>So <code>10000</code> is not a valid <code>enum</code> value. How would you personally find a solution to this? Would you encase the <code>map</code> access in a <code>try</code> block and <code>catch</code> the <code>exception</code>? What if I have many functions which access container information with user input enum values - would you then put <code>try catch</code> in all of them too?</p>