fork download
  1. #include <iostream>
  2.  
  3. constexpr long hash(const char* ptr) { return ptr[0] == '\0' ? 0 : ((hash(ptr + 1) << 1) ^ ptr[0]); }
  4.  
  5.  
  6. void my_method(const char* function)
  7. {
  8. switch(hash(function))
  9. {
  10. case hash("test1"): { std::cout << "test 1 got matched." << std::endl; } break;
  11. case hash("test2"): { std::cout << "test 2 got matched." << std::endl; } break;
  12. default: { std::cout << "test 1 got matched." << std::endl; } break;
  13. }
  14. }
  15.  
  16. int main(int argc, char** argv)
  17. {
  18. my_method("test1");
  19. my_method("test2");
  20. my_method("");
  21. }
Success #stdin #stdout 0s 4376KB
stdin
Standard input is empty
stdout
test 1 got matched.test 2 got matched.test 1 got matched.