diff --git a/include/infra/algo.h b/include/infra/algo.h index ac918fd0..bfe12e2e 100644 --- a/include/infra/algo.h +++ b/include/infra/algo.h @@ -139,6 +139,17 @@ auto find_in_map_required(MapType&& m, const typename std::decay_t::key return iter->second; } +template +auto find_in_map_required(MapType&& m, const typename std::decay_t::key_type& key, NotFoundMessageCallback&& cb) +{ + auto iter = m.find(key); + if (iter == m.end()) { + throw RuntimeError(cb(key)); + } + + return iter->second; +} + /* Search for an entry in the map that matches the predicate * The entry is returned as a pointer (nullptr when not found) * This funtion never throws