fork download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. namespace some_package {
  5. class type {
  6. long code_;
  7. public:
  8. constexpr type(long code):
  9. code_(code)
  10. {}
  11.  
  12. constexpr auto code() const {
  13. return code_;
  14. }
  15.  
  16. friend std::string to_string(type const &t) {
  17. return std::to_string(t.code());
  18. }
  19.  
  20. struct constants;
  21. };
  22.  
  23. struct type::constants {
  24. static constexpr type type1 = type(1);
  25. static constexpr type type2 = type(2);
  26. /* etc */
  27. };
  28. }
  29.  
  30.  
  31. int main() {
  32. std::cout << to_string(some_package::type::constants::type1);
  33. std::cout << some_package::type::constants::type2.code();
  34. return 0;
  35. }
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
12