Revert D6366352: [folly] Split get_default() into two for deferred default construction
[folly.git] / folly / MapUtil.h
index b95da417ffe3f353dde541e6845b201ba16806da..b1fbfadcaf59ecf3db6d14e80f35e472152fa249 100644 (file)
@@ -18,7 +18,6 @@
 
 #include <folly/Conv.h>
 #include <folly/Optional.h>
-#include <folly/functional/Invoke.h>
 #include <tuple>
 
 namespace folly {
@@ -27,27 +26,13 @@ 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>
-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{});
-}
-template <
-    class Map,
-    typename Key = typename Map::key_type,
-    typename Value = typename Map::mapped_type,
-    typename std::enable_if<!is_invocable<Value>::value>::type* = nullptr>
-typename Map::mapped_type
-get_default(const Map& map, const Key& key, Value&& dflt) {
+template <class Map, typename Key = typename Map::key_type>
+typename Map::mapped_type get_default(
+    const Map& map,
+    const Key& key,
+    const typename Map::mapped_type& dflt = typename Map::mapped_type()) {
   auto pos = map.find(key);
-  if (pos != map.end()) {
-    return pos->second;
-  } else {
-    // if elision from function parameters was allowed, then we could make the
-    // third parameter a value parameter and just elide that into the return
-    // value, but sadly that is not allowed (yet)
-    return std::forward<Value>(dflt);
-  }
+  return (pos != map.end() ? pos->second : dflt);
 }
 
 /**