title: C++ const exprssion members for switch case
body: <p>I would like some way to evaluate a switch-class statement using class members that are not integer or eum.</p>
  
  <p>The real question is how to make those class members <code>const-expression</code> i.e. those members must be known as constant at compile-time.</p>
  
  <p>I tried the code below with <code>static const</code>, but it works only when in the <code>case</code> statements there are integers.</p>
  
  <p>I was looking at new <code>C++11 constexpr</code> that would do the job.</p>
  
  <p>What If I have not available that keyword? Is there anyway or trick or anything to allow my class members (non integer or enum) being const expressions?</p>
  
  <p>I am using Linux and g++. Also any g++ specific keyword would be appreciated.</p>
  
  <pre><code>  class MyEnum
    {
    public:
      int val_;
      MyEnum(){}
      MyEnum(int v): val_(v){}
      operator int(){return val_;}
      static const MyEnum ALFA;
      static const MyEnum BETA;
      void foo() {
         // do something.
      }
    };
  
    const MyEnum MyEnum::ALFA(1);
    const MyEnum MyEnum::BETA(2);
  
    void testEnum()
    {
      MyEnum val = MyEnum::ALFA;
  
      switch(val)
      {
        case 0: //works
        //case MyEnum::ALFA:// doesn't work
        cout &lt;&lt; "ciao" &lt;&lt; endl;
        break;
        case 1: //works
        //case MyEnum::BETA: // doesn't work
        cout &lt;&lt; "bello" &lt;&lt; endl;
        break;
        default:
        break;
      } 
    }
  </code></pre>