fork(7) download
  1. #include<string>
  2. #include<iostream>
  3.  
  4. namespace notstd {
  5. namespace adl_helper {
  6. using std::to_string;
  7.  
  8. template<class T>
  9. std::string as_string( T&& t ) {
  10. return to_string( std::forward<T>(t) );
  11. }
  12. }
  13. template<class T>
  14. std::string to_string( T&& t ) {
  15. return adl_helper::as_string(std::forward<T>(t));
  16. }
  17. }
  18. namespace bob{
  19. class my_class{
  20. public:
  21. friend std::string to_string(my_class const& self) {
  22. return "I am " + notstd::to_string(self.i);
  23. }
  24. int i;
  25. };
  26. }
  27. int main(){
  28. bob::my_class x{1};
  29. std::cout << notstd::to_string(x)<<"\n";
  30. }
Success #stdin #stdout 0s 5520KB
stdin
Standard input is empty
stdout
I am 1