X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2FMapUtil.h;h=598567a7682a435b9a9936d1b487553aa1156c30;hb=94e964976c1b65e79b0f7bdd960cfec260399a52;hp=f042bd2d5e86f328d4c0df508cb79a3aecc44d7a;hpb=12244d01218f5ca032b61cd8f779a7fe91b40bf3;p=folly.git diff --git a/folly/MapUtil.h b/folly/MapUtil.h index f042bd2d..598567a7 100644 --- a/folly/MapUtil.h +++ b/folly/MapUtil.h @@ -55,8 +55,21 @@ get_default(const Map& map, const typename Map::key_type& key, Func&& dflt) { * or throw an exception of the specified type. */ template -typename Map::mapped_type get_or_throw( - const Map& map, const typename Map::key_type& key, +const typename Map::mapped_type& get_or_throw( + const Map& map, + const typename Map::key_type& key, + const std::string& exceptionStrPrefix = std::string()) { + auto pos = map.find(key); + if (pos != map.end()) { + return pos->second; + } + throw E(folly::to(exceptionStrPrefix, key)); +} + +template +typename Map::mapped_type& get_or_throw( + Map& map, + const typename Map::key_type& key, const std::string& exceptionStrPrefix = std::string()) { auto pos = map.find(key); if (pos != map.end()) { @@ -103,7 +116,9 @@ template < typename Func, typename = typename std::enable_if::type, - const typename Map::mapped_type&>::value>::type> + const typename Map::mapped_type&>::value>::type, + typename = typename std::enable_if< + std::is_reference::type>::value>::type> const typename Map::mapped_type& get_ref_default( const Map& map, const typename Map::key_type& key,