| 2244 | string_t, typename std::decay<ValueType>::type >; |
| 2245 | |
| 2246 | public: |
| 2247 | /// @brief access specified object element with default value |
| 2248 | /// @sa https://json.nlohmann.me/api/basic_json/value/ |
| 2249 | template < class ValueType, detail::enable_if_t < |
| 2250 | !detail::is_transparent<object_comparator_t>::value |
| 2251 | && detail::is_getable<basic_json_t, ValueType>::value |
| 2252 | && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value, int > = 0 > |
| 2253 | ValueType value(const typename object_t::key_type& key, const ValueType& default_value) const |
| 2254 | { |
| 2255 | // value only works for objects |
| 2256 | if (JSON_HEDLEY_LIKELY(is_object())) |
| 2257 | { |
| 2258 | // If 'key' is found, return its value. Otherwise, return `default_value'. |
| 2259 | const auto it = find(key); |
| 2260 | if (it != end()) |
| 2261 | { |
| 2262 | return it->template get<ValueType>(); |
| 2263 | } |
| 2264 | |
| 2265 | return default_value; |
| 2266 | } |
| 2267 | |
| 2268 | JSON_THROW(type_error::create(306, detail::concat("cannot use value() with ", type_name()), this)); |
| 2269 | } |
| 2270 | |
| 2271 | /// @brief access specified object element with default value |
| 2272 | /// @sa https://json.nlohmann.me/api/basic_json/value/ |