문제

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.

도움이 되었습니까?

해결책

My version of GCC is happy to accept:

template<typename T>
struct A;

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

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top