fork download
  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <boost/type_traits.hpp>
  4. #include <boost/utility/enable_if.hpp>
  5.  
  6. template<typename T>
  7. struct Foo
  8. {
  9. typename boost::enable_if_c<boost::is_same<char,T>::value >::type
  10. bar();
  11.  
  12. typename boost::disable_if_c<boost::is_same<char,T>::value >::type
  13. bar();
  14. };
  15.  
  16. template<typename T>
  17. typename boost::disable_if_c<boost::is_same<char,T>::value >::type
  18. Foo<T>::bar()
  19. {
  20. std::cout << "I am generic ..." << std::endl;
  21. }
  22.  
  23. template<typename T>
  24. typename boost::enable_if_c<boost::is_same<char,T>::value >::type
  25. Foo<T>::bar()
  26. {
  27. std::cout << "I am specific ..." << std::endl;
  28. }
  29.  
  30. int main()
  31. {
  32. Foo<char> f1;
  33. f1.bar();
  34.  
  35. return EXIT_SUCCESS;
  36. }
  37.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:13: error: ‘typename boost::disable_if_c<boost::is_same::value, void>::type Foo<T>::bar()’ cannot be overloaded
prog.cpp:10: error: with ‘typename boost::enable_if_c<boost::is_same::value, void>::type Foo<T>::bar()’
prog.cpp:18: error: prototype for ‘typename boost::disable_if_c<boost::is_same::value, void>::type Foo<T>::bar()’ does not match any in class ‘Foo<T>’
prog.cpp:10: error: candidate is: typename boost::enable_if_c<boost::is_same::value, void>::type Foo<T>::bar()
stdout
Standard output is empty