fork(1) download
  1. #include <memory>
  2. #include <sstream>
  3. #include <string>
  4.  
  5. class MyClass {};
  6.  
  7. bool Post(std::string command, std::string payload) {return false;}
  8. std::string Get(std::string command) { return ""; }
  9. bool Delete(std::string command, std::string name) { return false;}
  10. int OtherFunc(std::string command, bool enabled, const MyClass& name) {return 0;}
  11.  
  12. enum class CommandType
  13. {
  14. Get, Post, Delete, OtherFunc
  15. };
  16.  
  17.  
  18. template<typename ... Ts>
  19. typename std::enable_if<sizeof...(Ts) != 2, int>::type
  20. Post (Ts&&...) {return 0;}
  21.  
  22. template<typename ... Ts>
  23. typename std::enable_if<sizeof...(Ts) != 2, int>::type
  24. Delete (Ts&&...) {return 0;}
  25.  
  26. template<typename ... Ts>
  27. typename std::enable_if<sizeof...(Ts) != 3, int>::type
  28. OtherFunc (Ts&&...) {return 0;}
  29.  
  30. template< typename... Params>
  31. std::unique_ptr<std::stringstream> Execute(CommandType command, Params... parameters) {
  32. auto response = std::make_unique<std::stringstream>();
  33. if(command == CommandType::Get)
  34. *response << Get(parameters...);
  35. else if(command == CommandType::Post)
  36. *response << Post(parameters...);
  37. else if(command == CommandType::Delete)
  38. *response << Delete(parameters...);
  39. else if(command == CommandType::OtherFunc)
  40. *response << OtherFunc(parameters...);
  41.  
  42. return response;
  43. }
  44.  
  45.  
  46. int main(){
  47. Execute(CommandType::Get, "hello");
  48. }
  49.  
Success #stdin #stdout 0s 3268KB
stdin
Standard input is empty
stdout
Standard output is empty