Skip to content

Commit

Permalink
Add default template param for map key in MapUtil
Browse files Browse the repository at this point in the history
Summary:
I've got this codemod that is turning `stl::mapGetDefault` -> `folly::get_default`, and noticed one of the generated diffs failed to compile: D66440835

Compiler couldn't infer the `{p1, p2}` key as a pair type, and noticed that we just need to give it a bit of a hint.

Reviewed By: Gownta

Differential Revision: D66450949

fbshipit-source-id: 7e0f1487a3954eda6574c3bc4d4b1d0cb0ac7bb1
  • Loading branch information
cjhawley authored and facebook-github-bot committed Nov 26, 2024
1 parent faab792 commit 58977df
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion third-party/folly/src/folly/container/MapUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace folly {
* Given a map and a key, return the value corresponding to the key in the map,
* or a given default value if the key doesn't exist in the map.
*/
template <typename Map, typename Key>
template <typename Map, typename Key = typename Map::key_type>
typename Map::mapped_type get_default(const Map& map, const Key& key) {
auto pos = map.find(key);
return (pos != map.end()) ? (pos->second) : (typename Map::mapped_type{});
Expand Down

0 comments on commit 58977df

Please sign in to comment.