fork(7) download
  1. #include <iostream>
  2.  
  3. template<typename T>
  4. struct to_void
  5. {
  6. typedef void type;
  7. };
  8.  
  9. class Foo
  10. {
  11. typedef int TD;
  12. };
  13.  
  14. template <typename T, typename dummy = void>
  15. struct has_TD : std::false_type {};
  16.  
  17. template <typename T>
  18. struct has_TD<T, typename to_void<typename T::TD>::type > : std::true_type{};
  19.  
  20. int main()
  21. {
  22. std::cout << std::boolalpha << has_TD<Foo>::value << std::endl;
  23. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In instantiation of 'struct has_TD<Foo>':
prog.cpp:22:44:   required from here
prog.cpp:11:14: error: 'typedef int Foo::TD' is private
  typedef int TD;
              ^
prog.cpp:18:75: error: within this context
 struct has_TD<T, typename to_void<typename T::TD>::type > : std::true_type{};
                                                                           ^
prog.cpp:11:14: error: 'typedef int Foo::TD' is private
  typedef int TD;
              ^
prog.cpp:18:75: error: within this context
 struct has_TD<T, typename to_void<typename T::TD>::type > : std::true_type{};
                                                                           ^
prog.cpp: In function 'int main()':
prog.cpp:11:14: error: 'typedef int Foo::TD' is private
  typedef int TD;
              ^
prog.cpp:22:33: error: within this context
  std::cout << std::boolalpha << has_TD<Foo>::value << std::endl;
                                 ^
stdout
Standard output is empty