Limit range of type template arguments for class
问题 How can I have this effect without the arbitrary typedefs? #include <type_traits> #include <iostream> typedef int Primary; typedef float Secondary; template<Class C, std::enable_if<std::is_same<Class, Primary>::value || std::is_same<Class, Secondary>::value> = 0> class Entity { public: template<std::enable_if<std::is_same<Class, Secondary>::value>::type = 0> void onlyLegalForSecondaryEntities() { std::cout << "Works" << std::endl; } }; int main() { Entity<Secondary> e; e