Lifetime issue using containers
Closed this issue · 0 comments
pfultz2 commented
#include <unordered_map>
template <class T, class K, class V>
const V& get_default(const T& t, const K& k, const V& v) {
auto it = t.find(k);
if (it == t.end()) return v;
return it->second;
}
const int& bar(const std::unordered_map<int, int>& m, int k) {
return get_default(m, k, 0);
}