Skip to content

Instantly share code, notes, and snippets.

@ilpropheta
Created July 16, 2016 14:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ilpropheta/5cc76e9d055f949699e4c61b7fe6b8c1 to your computer and use it in GitHub Desktop.
Save ilpropheta/5cc76e9d055f949699e4c61b7fe6b8c1 to your computer and use it in GitHub Desktop.
template<typename Gen>
ValueType fetch_or_insert(const Key& key, Gen g)
{
auto it = data.find(key);
if (it != end(data))
{
return it->second;
}
return data.emplace(key, g()).first->second;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment