fork(8) download
  1. #define OPTION 1 // OPTION 2 : broken, OPTION 1 : works
  2.  
  3. #include <iostream>
  4. #include <type_traits>
  5. using namespace std;
  6.  
  7.  
  8. template <typename T,typename Enable=void>
  9. struct child;
  10.  
  11. template <typename T>
  12. struct base
  13. {
  14. typedef T type;
  15.  
  16. #if OPTION ==1
  17. struct base_tag{};
  18.  
  19. #endif
  20.  
  21. };
  22.  
  23.  
  24. #if OPTION ==2
  25. template <typename T>
  26. struct child < T, typename std::enable_if < std::is_base_of< base<typename T::type>, T>::value>::type>
  27. {
  28.  
  29. const char* value = "specialization";
  30. };
  31. #else
  32.  
  33. template <typename T>
  34. struct child < T, std::void_t<typename T::base_tag> >
  35. {
  36.  
  37. const char* value = "specialization";
  38. };
  39.  
  40. #endif
  41.  
  42.  
  43.  
  44. template <typename T>
  45. struct dervived : base<T>
  46. {
  47. child<dervived> child_;
  48. typedef T type;
  49. };
  50.  
  51.  
  52.  
  53. int main() {
  54.  
  55.  
  56. std::cout << dervived<int>().child_.value << std::endl;
  57. return 0;
  58. }
Success #stdin #stdout 0s 4516KB
stdin
Standard input is empty
stdout
specialization