fork download
  1. #include <iostream>
  2. #include <map>
  3.  
  4.  
  5. int main() {
  6. std::map<std::string, int> cache {{"Hello", 42}};
  7.  
  8. auto p = cache.emplace("Hi", 0);
  9. auto& hi = p.first->second;
  10. if (p.second) {
  11. hi = 51; // Heavy computation.
  12. }
  13. std::cout << hi << std::endl;
  14. }
  15.  
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
51