Can you specialize in using assertions?

If I want some type to be specialized in its template parameter, I usually use struct:

template <bool value>
struct IsTrue;

template <>
struct IsTrue<true> : std::true_type {};

template <>
struct IsTrue<false> : std::false_type {};

      

An empty struct, which derives its only functionality from inheritance, is not actually different from an operator using

, so I was wondering if something like template specialization exists for operators using

? The pseudocode of what I'm following is below:

template <bool value>
using IsTrue;

template <>
using IsTrue<true> = std::true_type;

template <>
using IsTrue<false> = std::false_type;

      

Is something like this possible? What would it be called?

+3


source to share


1 answer


No, alias templates cannot be partially or explicitly specialized.

The earlier design allowed for specialization, but the resulting semantics are rather ... odd, at least from today's angle. For example, with this construction, the following program will declare two different function templates:

template<class, class> class Meow {};
template<class T> using MeowInt = Meow<int, T>;
template<class> void f(Meow<int, T>);
template<class> void f(MeowInt<T>);

      



and this call won't compile because you won't be able to deduce the template argument:

template<class T> using Purr = T;
template<class T> void f(Purr<T>);

f(42);

      

+3


source







All Articles