Skip to content

Instantly share code, notes, and snippets.

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/d9e1301a1de4ad96ca2d917b4b89d470 to your computer and use it in GitHub Desktop.
Save ilpropheta/d9e1301a1de4ad96ca2d917b4b89d470 to your computer and use it in GitHub Desktop.
template<typename Gen>
ValueType fetch_or_insert(const Key& key, Gen g)
{
const auto er = data.equal_range(key);
if (er.first != er.second)
{
return er.first->second;
}
return data.emplace_hint(er.first, key, g())->second;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment