std::type_index를 사용하면 타입을 id로 사용한 container를 사용할 수 있습니다.
#include <iostream> #include <unordered_map> #include <type_traits> #include <typeindex> #include <functional> using namespace std; unordered_map<type_index, function<void()>> mapType; template<typename T> void WhatIsThis(T) { mapType[typeid(T)](); } int main() { mapType.emplace(typeid(int), []{cout << "this is int" << endl;}); mapType.emplace(typeid(float), []{cout << "this is float" << endl;}); mapType.emplace(typeid(double), []{cout << "this is double" << endl;}); mapType.emplace(typeid(const char*), []{cout << "this is const char*" << endl;}); WhatIsThis(1); WhatIsThis(0.5f); WhatIsThis(0.5); WhatIsThis("Hello world"); return 0; }