How to deduce types by template integers in C++

I have code: template<int I, typename = void> struct indexed_type { using type = void; indexed_type() { std::cout << "I is void: " << I << std::endl; } }; template<int I> struct indexed_type<I, typename std::enable_if<I == 1, char>::type> { using type = char; indexed_type() { std::cout << "I is char: " << I << std::endl;… Read More How to deduce types by template integers in C++

Check if a type is the same as a templated type

I have a user defined class template<typename T, int N> class MyClass { // Implementation }; and I want to check on the instantiation of another class if its template parameter is an instance of MyClass template<typename T, std::enable_if_t<!is_MyClass<T>, bool> = true> class MapClass { // custom stuff here }; template<typename T, std::enable_if_t<is_MyClass<T>, bool> =… Read More Check if a type is the same as a templated type

What I need write this second SFINAE constructor?

I wanted to activate a class with parameter packs when all types in the parameter pack is distinct. I wrote a small helper function like this that works with no problem: template<typename T, typename… Ts> constexpr bool has_duplicate_types() { if constexpr (sizeof…(Ts) == 0) return false; else return ((std::is_same_v<std::decay_t<T>, std::decay_t<Ts>> || …) || has_duplicate_types<Ts…>()); }… Read More What I need write this second SFINAE constructor?