fork download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. struct player_name_tag {} PLAYER_NAME;
  5. struct connection_timeout_tag {} CONNECTION_TIMEOUT;
  6.  
  7. template<class T>
  8. struct constref_wrapper {
  9. constref_wrapper(const T& x) noexcept
  10. : content(x) {}
  11.  
  12. const T& getValue() const noexcept {
  13. return content;
  14. }
  15.  
  16. private:
  17. const T& content;
  18. };
  19.  
  20. struct ResourceManager {
  21. static constref_wrapper<std::string> get(player_name_tag) {
  22. return constref_wrapper<std::string>(name);
  23. }
  24.  
  25. static constref_wrapper<int> get(connection_timeout_tag) {
  26. return constref_wrapper<int>(timeout);
  27. }
  28.  
  29. private:
  30. static std::string name;
  31. static int timeout;
  32. };
  33.  
  34. std::string ResourceManager::name = "Rambo";
  35. int ResourceManager::timeout = 100;
  36.  
  37. int main() {
  38. std::cout << ResourceManager::get(PLAYER_NAME).getValue() << std::endl;
  39. std::cout << ResourceManager::get(CONNECTION_TIMEOUT).getValue() << std::endl;
  40. }
Success #stdin #stdout 0s 4292KB
stdin
Standard input is empty
stdout
Rambo
100