Skip to content

Instantly share code, notes, and snippets.

@ilpropheta
Last active July 19, 2016 17:58
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/4c6e39bc6dfe508922403a5137d68a26 to your computer and use it in GitHub Desktop.
Save ilpropheta/4c6e39bc6dfe508922403a5137d68a26 to your computer and use it in GitHub Desktop.
template<typename Gen>
ValueType fetch_or_insert(const Key& key, Gen g)
{
const auto lb = data.lower_bound(key);
if (lb != end(data) && !(data.key_comp()(key, lb->first)))
{
return lb->second;
}
return data.emplace_hint(lb, key, g())->second;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment