Last active
July 19, 2016 17:58
-
-
Save ilpropheta/4c6e39bc6dfe508922403a5137d68a26 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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