fork download
  1.  
  2. #include <string>
  3. #include <iostream>
  4. class foo {
  5. };
  6.  
  7. class bar {
  8. public:
  9. const foo & to_foo() const {
  10. return f;
  11. }
  12.  
  13. foo & to_foo() {
  14. return f;
  15. }
  16. private:
  17. foo f;
  18. };
  19.  
  20. template< typename T, typename Enable = void>
  21. class convert {};
  22.  
  23. template< typename T>
  24. struct convert<T>{
  25. static const foo & call1( const bar & b ) {
  26. std::cout<<"call1"<<std::endl;
  27. return b.to_foo();
  28. }
  29.  
  30. static foo & call2( bar & b ) {
  31. std::cout<<"call2"<<std::endl;
  32. return b.to_foo();
  33. }
  34. };
  35. int main()
  36. {
  37. bar b;
  38. const bar cb = b;
  39. convert<std::string> converter;
  40. converter.call1(cb);
  41. converter.call2(b);
  42.  
  43. return 0;
  44. }
  45.  
Success #stdin #stdout 0.01s 2724KB
stdin
Standard input is empty
stdout
call1
call2