Domanda

I'm asking myself

Can you write a class template and a corresponding partial specialization such that for any set of template arguments for the parameters, the partial specialization is taken by the compiler?

For example

template<typename T>
struct A { };

template<typename T>
struct A</* what to write!?*/> { };

I seem to remember having read that this is possible somehow, but I forgot the exact algorithm to make this work.

È stato utile?

Soluzione

My version of GCC is happy to accept:

template<typename T>
struct A;

template<typename... Pack>
struct A<Pack...> {};

Altri suggerimenti

If you allow SFINAE trick then, it will be as easy as this:

enum E { TRUE };

template<typename T, E = TRUE>
struct A
{
  static const bool value = false;
};

template<typename T>
struct A<T, TRUE>
{
  static const bool value = true;
};

Demo.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top