fork download
  1. #include <iostream>
  2. #include <sstream>
  3. using namespace std;
  4.  
  5. #define VERSATILE_LITERAL(suffix, implementation) \
  6.   auto operator "" suffix(unsigned long long x ) { return implementation(#suffix, x); } \
  7.   auto operator "" suffix(long double x ) { return implementation(#suffix, x); } \
  8.   auto operator "" suffix(char x ) { return implementation(#suffix, x); } \
  9.   auto operator "" suffix(wchar_t x ) { return implementation(#suffix, x); } \
  10.   auto operator "" suffix(const char* x, size_t len) { return implementation(#suffix, x); } \
  11.   auto operator "" suffix(const wchar_t* x, size_t len) { return implementation(#suffix, x); } \
  12. //endmacro
  13.  
  14. template<class T> string id(const char* s, T t)
  15. {
  16. ostringstream o;
  17. o << s << "(" << t << ")" << " " << __PRETTY_FUNCTION__;
  18. return o.str();
  19. }
  20.  
  21.  
  22. VERSATILE_LITERAL(_id, id)
  23. VERSATILE_LITERAL(_ego, id)
  24. VERSATILE_LITERAL(_superego, id)
  25.  
  26. int main() {
  27. cout << 123_id << endl;
  28. cout << 123._ego << endl;
  29. cout << "hello"_superego << endl;
  30. }
  31.  
Success #stdin #stdout 0s 16080KB
stdin
Standard input is empty
stdout
_id(123) std::__cxx11::string id(const char*, T) [with T = long long unsigned int; std::__cxx11::string = std::__cxx11::basic_string<char>]
_ego(123) std::__cxx11::string id(const char*, T) [with T = long double; std::__cxx11::string = std::__cxx11::basic_string<char>]
_superego(hello) std::__cxx11::string id(const char*, T) [with T = const char*; std::__cxx11::string = std::__cxx11::basic_string<char>]