diff options
Diffstat (limited to 'src/libutil/util.hh')
-rw-r--r-- | src/libutil/util.hh | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/libutil/util.hh b/src/libutil/util.hh index a889ef2f14fa..b714cdc64a5a 100644 --- a/src/libutil/util.hh +++ b/src/libutil/util.hh @@ -413,4 +413,14 @@ string base64Encode(const string & s); string base64Decode(const string & s); +/* Get a value for the specified key from an associate container, or a + default value if the key doesn't exist. */ +template <class T> +string get(const T & map, const string & key, const string & def = "") +{ + auto i = map.find(key); + return i == map.end() ? def : i->second; +} + + } |