MCPcopy Create free account
hub / github.com/CodingGay/BlackDex / GetOrCreate

Method GetOrCreate

Bcore/src/main/cpp/base/safe_map.h:132–141  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

130
131 template <typename CreateFn>
132 V GetOrCreate(const K& k, CreateFn create) {
133 static_assert(std::is_same<V, typename std::result_of<CreateFn()>::type>::value,
134 "Argument `create` should return a value of type V.");
135 auto lb = lower_bound(k);
136 if (lb != end() && !key_comp()(k, lb->first)) {
137 return lb->second;
138 }
139 auto it = PutBefore(lb, k, create());
140 return it->second;
141 }
142
143 iterator FindOrAdd(const K& k, const V& v) {
144 iterator it = find(k);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected