fork(5) download
  1. #include <iostream>
  2.  
  3. template<template<typename...> class C, typename... T>
  4. struct is_valid_specialization {
  5. typedef struct { char _; } yes;
  6. typedef struct { yes _[2]; } no;
  7.  
  8. template<template<typename...> class D, typename... U>
  9. static yes test(D<U...>*);
  10. template<template<typename...> class D, typename... U>
  11. static no test(...);
  12.  
  13. constexpr static bool value = (sizeof(test<C, T...>(0)) == sizeof(yes));
  14. };
  15.  
  16. template<typename T>
  17. struct Test1 { };
  18.  
  19. template<typename T1, typename T2>
  20. struct Test2 { };
  21.  
  22. template<typename...>
  23. struct TestV { };
  24.  
  25. int main() {
  26. std::cout << "Test1<T>: " << is_valid_specialization<Test1, int>::value << std::endl;
  27. std::cout << "Test2<T>: " << is_valid_specialization<Test2, int>::value << std::endl;
  28. std::cout << "TestV<T>: " << is_valid_specialization<TestV, int>::value << std::endl;
  29. }
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
Test1<T>: 0
Test2<T>: 0
TestV<T>: 0