fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. enum class E { e0, e1, e2, e3, };
  6.  
  7. static constexpr E get(int S)
  8. {
  9. switch(S)
  10. {
  11. case 0: return E::e0;
  12. case 1: return E::e1;
  13. case 2: return E::e2;
  14. default: return E::e3;
  15. }
  16. }
  17.  
  18. template <int S>
  19. class C {
  20. public:
  21. static const E e = get(S);
  22. void out() const { cout << "e = " << int(e) << endl; }
  23.  
  24. };
  25.  
  26. int main(int argc, const char * argv[])
  27. {
  28. C<1>().out();
  29. C<2>().out();
  30. C<123>().out();
  31. }
  32.  
Success #stdin #stdout 0s 4244KB
stdin
Standard input is empty
stdout
e = 1
e = 2
e = 3