fork download
  1. #include <map>
  2. #include <string>
  3. #include <iostream>
  4.  
  5. enum class foo {
  6. bar, baz, qux
  7. };
  8.  
  9. foo meh(const std::string& mooh) {
  10. static std::map<std::string, foo> map{
  11. { "bar", foo::bar },
  12. { "baz", foo::baz },
  13. { "qux", foo::qux },
  14. };
  15.  
  16. return map.at(mooh);
  17. }
  18.  
  19. int main() {
  20. std::cout << (meh("bar") == foo::bar) << '\n';
  21. std::cout << (meh("baz") == foo::baz) << '\n';
  22. std::cout << (meh("qux") == foo::qux) << '\n';
  23. meh("out_of_range");
  24. }
  25.  
Runtime error #stdin #stdout 0s 2964KB
stdin
Standard input is empty
stdout
1
1
1