fork download
  1. #include <iostream>
  2. #include <utility>
  3. #include <boost/type_traits.hpp>
  4.  
  5. struct Bar { virtual ~Bar() {} };
  6. struct Foo: Bar {};
  7. struct Faz {};
  8.  
  9. template <typename T>
  10. typename boost::enable_if<boost::is_base_of<Bar, T>>::type
  11. foo(char const* type, T) {
  12. std::cout << type << " is derived from Bar\n";
  13. }
  14. template <typename T>
  15. typename boost::disable_if<boost::is_base_of<Bar, T>>::type
  16.  
  17. foo(char const* type, T) {
  18. std::cout << type << " is NOT derived from Bar\n";
  19. }
  20.  
  21. int main()
  22. {
  23. foo("Foo", Foo());
  24. foo("Faz", Faz());
  25. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:10: error: ‘enable_if’ in namespace ‘boost’ does not name a type
prog.cpp:10: error: expected unqualified-id before ‘<’ token
prog.cpp:15: error: ‘disable_if’ in namespace ‘boost’ does not name a type
prog.cpp:15: error: expected unqualified-id before ‘<’ token
prog.cpp: In function ‘int main()’:
prog.cpp:23: error: ‘foo’ was not declared in this scope
stdout
Standard output is empty