+/**
+ * Given a map and a path of keys, return the value corresponding to the nested
+ * value, or a given default value if the path doesn't exist in the map.
+ * The default value is the last parameter, and is copied when returned.
+ */
+template <
+ class Map,
+ class Key1,
+ class Key2,
+ class... KeysDefault,
+ typename = typename std::enable_if<sizeof...(KeysDefault) != 0>::type>
+auto get_default(
+ const Map& map,
+ const Key1& key1,
+ const Key2& key2,
+ const KeysDefault&... keysDefault) ->
+ typename detail::NestedMapType<Map, 1 + sizeof...(KeysDefault)>::type {
+ if (const auto* ptr = get_ptr(map, key1)) {
+ return get_default(*ptr, key2, keysDefault...);
+ }
+ return detail::extract_default(keysDefault...);
+}
+
+/**
+ * Given a map and a path of keys, return a reference to the value corresponding
+ * to the nested value, or the given default reference if the path doesn't exist
+ * in the map.
+ * The default value is the last parameter, and must be a lvalue reference.
+ */
+template <
+ class Map,
+ class Key1,
+ class Key2,
+ class... KeysDefault,
+ typename = typename std::enable_if<sizeof...(KeysDefault) != 0>::type,
+ typename = typename std::enable_if<std::is_lvalue_reference<
+ typename detail::DefaultType<KeysDefault...>::type>::value>::type>
+auto get_ref_default(
+ const Map& map,
+ const Key1& key1,
+ const Key2& key2,
+ KeysDefault&&... keysDefault) ->
+ typename detail::NestedMapType<Map, 1 + sizeof...(KeysDefault)>::type
+ const& {
+ if (const auto* ptr = get_ptr(map, key1)) {
+ return get_ref_default(*ptr, key2, keysDefault...);
+ }
+ return detail::extract_default(keysDefault...);
+}
+} // namespace folly