fork(4) download
  1. #include <unordered_map>
  2. #include <string>
  3. #include <utility>
  4.  
  5. struct BeliefCondFunc
  6. {
  7. using cb_type = bool(*)();
  8. static std::unordered_map<std::string, cb_type> const FuncMap;
  9.  
  10. static bool Greater(int A, int B)
  11. {
  12. return A > B;
  13. }
  14.  
  15. static bool Between(float A, float B, float C)
  16. {
  17. return A > B && A < C;
  18. }
  19.  
  20. template<typename ...Args>
  21. static bool call(std::string const& key, Args&&... args){
  22. using prototype = bool(*)(Args...);
  23. return reinterpret_cast<prototype>(FuncMap.at(key))(std::forward<Args>(args)...);
  24. };
  25. };
  26.  
  27. std::unordered_map<std::string, BeliefCondFunc::cb_type> const BeliefCondFunc::FuncMap {
  28. {"Greater", reinterpret_cast<cb_type>(&BeliefCondFunc::Greater) },
  29. {"Between", reinterpret_cast<cb_type>(&BeliefCondFunc::Between) }
  30. };
  31.  
  32. int main() {
  33. BeliefCondFunc::call("Greater", 1, 2);
  34. return 0;
  35. }
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
Standard output is empty