fork download
  1. #include<type_traits>
  2.  
  3. class foo {
  4. };
  5.  
  6. class bar {
  7. public:
  8. const foo & to_foo() const {
  9. return f;
  10. }
  11.  
  12. foo & to_foo() {
  13. return f;
  14. }
  15. private:
  16. foo f;
  17. };
  18.  
  19. template< typename T, typename Enable = void >
  20. class convert {};
  21.  
  22. template< typename T >
  23. struct convert< T, typename std::enable_if< std::is_member_function_pointer< decltype( &T::to_foo ) >::value >::type > {
  24. static const foo & call1( const bar & b ) {
  25. return b.to_foo();
  26. }
  27.  
  28. static foo & call2( bar & b ) {
  29. return b.to_foo();
  30. }
  31. };
  32.  
  33. int main() {
  34. bar b;
  35. foo & f = convert<bar>::call2( b );
  36. return 0;
  37. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'int main()':
prog.cpp:35:25: error: type of '& bar::to_foo' is unknown
prog.cpp:35:13: error: 'call2' is not a member of 'convert<bar>'
stdout
Standard output is empty