fork download
  1. #include <typeinfo>
  2. #include <vector>
  3. #include <stdexcept>
  4. #include <string>
  5.  
  6. typedef bool (*FP)(const std::string&);
  7. typedef std::vector<FP> FPData;
  8.  
  9. std::size_t IDFind(const std::string& ID, const FPData& FP) {
  10.  
  11. for (std::size_t i = 0; i < FP.size(); i++) {
  12. if (FP[i](ID)) { return i; }
  13. }
  14.  
  15. return FP.size();
  16.  
  17. }
  18.  
  19. template<class R,class... Arg>
  20. R Factory(std::size_t N, const Arg& ... A) {
  21.  
  22. switch (N)
  23. {
  24. case 0:
  25. return int(A...);
  26. case 1:
  27. return double(A...);
  28. default:
  29. throw std::logic_error("function Factory. by Default case.");
  30. break;
  31. }
  32. }
  33.  
  34. template<class T>
  35. bool ID_Check(const std::string& in) {
  36. return typeid(T).name() == in;
  37. }
  38.  
  39. int main() {
  40. auto R = Factory<int>(IDFind(typeid(int).name(), { ID_Check<int>,ID_Check<double> }), 0);
  41.  
  42. return 0;
  43. }
Success #stdin #stdout 0s 4560KB
stdin
Standard input is empty
stdout
Standard output is empty