| 3987 | detail::is_getable<basic_json_t, ValueType>::value |
| 3988 | && !std::is_same<value_t, ValueType>::value, int >::type = 0 > |
| 3989 | ValueType value(const typename object_t::key_type& key, const ValueType& default_value) const |
| 3990 | { |
| 3991 | // at only works for objects |
| 3992 | if (JSON_HEDLEY_LIKELY(is_object())) |
| 3993 | { |
| 3994 | // if key is found, return value and given default value otherwise |
| 3995 | const auto it = find(key); |
| 3996 | if (it != end()) |
| 3997 | { |
| 3998 | return it->template get<ValueType>(); |
| 3999 | } |
| 4000 | |
| 4001 | return default_value; |
| 4002 | } |
| 4003 | |
| 4004 | JSON_THROW(type_error::create(306, "cannot use value() with " + std::string(type_name()), *this)); |
| 4005 | } |
| 4006 | |
| 4007 | /*! |
| 4008 | @brief overload for a default value of type const char* |