| 18001 | template<class ValueType, typename std::enable_if< |
| 18002 | std::is_convertible<basic_json_t, ValueType>::value, int>::type = 0> |
| 18003 | ValueType value(const typename object_t::key_type& key, const ValueType& default_value) const |
| 18004 | { |
| 18005 | // at only works for objects |
| 18006 | if (JSON_HEDLEY_LIKELY(is_object())) |
| 18007 | { |
| 18008 | // if key is found, return value and given default value otherwise |
| 18009 | const auto it = find(key); |
| 18010 | if (it != end()) |
| 18011 | { |
| 18012 | return *it; |
| 18013 | } |
| 18014 | |
| 18015 | return default_value; |
| 18016 | } |
| 18017 | |
| 18018 | JSON_THROW(type_error::create(306, "cannot use value() with " + std::string(type_name()))); |
| 18019 | } |
| 18020 | |
| 18021 | /*! |
| 18022 | @brief overload for a default value of type const char* |