3

Is it somehow possible to check during compile time whether T is a primary template or a specialization? Expected usage:

template <typename>
struct foo{};

template <>
struct foo<double>{};

static_assert(is_primary_template<foo<int>>::value);
static_assert(!is_primary_template<foo<double>>::value);

It must yield true for a type instantiated from a primary template and false for template specialization.

I can't think of a way to implement this, rather with some workaround using type tags

template <typename T> 
using is_primary_template = std::is_base_of<primary_template, T>;
Sergey Kolesnik
  • 3,009
  • 1
  • 8
  • 28
  • Does this answer your question? [How to determine the primary template of a function specialization?](https://stackoverflow.com/questions/40284153/how-to-determine-the-primary-template-of-a-function-specialization) – infinitezero Dec 04 '21 at 22:11
  • @infinitezero no, that question is about differences in definitions - completelly different question. – Sergey Kolesnik Dec 04 '21 at 22:18

0 Answers0