#include <iostream> #include <string> #include <type_traits> using namespace std; template<typename T> constexpr size_t typeJudgeHelper() { constexpr size_t t = 1; constexpr size_t f = 0; if constexpr (is_same_v<std::string, T>) { return f; } else if (is_same_v<int, T>) { return f; } else if (is_same_v<double, T>) return f; else return t; }
template<typename T> void typeProcess() { if constexpr (is_same_v<std::string, T>) { cout << "string" << endl; } else if (is_same_v<int, T>) { cout << "int" << endl; }
}
template<typename... Args> auto TypeSplicing(Args&&...args) { constexpr size_t failsNum = (typeJudgeHelper<Args>() + ...); static_assert(failsNum == 0);
(typeProcess<Args>() , ...); }
int main() { TypeSplicing(std::string(""), 1); return 0; }
|