Recently, I began to study modern metaprogramming of templates, and I wrote myself an index_of function for types.
template<std::size_t Index, class C, class A> struct mp_index_of_impl{}; template<std::size_t Index, class C,template<class...> class A,class ...Ts> struct mp_index_of_impl<Index,C,A<C,Ts...>>{ using type = std::integral_constant<std::size_t,Index>; }; template<std::size_t Index, class C,template<class...> class A,class ...Ts,class T1> struct mp_index_of_impl<Index,C,A<T1,Ts...>>{ using type = typename mp_index_of_impl<Index + 1,C,A<Ts...>>::type; }; template<std::size_t Index, class C,template<class...> class A> struct mp_index_of_impl<Index,C,A<>>{
The problem is my last specialization
template<std::size_t Index, class C,template<class...> class A> struct mp_index_of_impl<Index,C,A<>>{
I tried using static_assert similar to this
template<std::size_t Index, class C,template<class...> class A> struct mp_index_of_impl<Index,C,A<>>{ static_assert(false,"Does not contain type"); };
But this will cause a compilation error every time, even if it does not match.
I want to throw a compilation error with a special error message if this template specification is matched. How can I do it?