mirror of
https://github.com/nlohmann/json.git
synced 2026-10-20 21:18:15 +00:00
Keep detail::negation out of json_view.hpp's enable_ifs
include-what-you-use asks json_view.hpp to include detail/meta/type_traits.hpp for it, which the single header must not do (the amalgamation would duplicate json's internals). The two conditions of value() go through a trait in value.hpp, like the others. Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
2 files changed
+8
-3
No files matched your search
@@ -12,7 +12,7 @@
|
|||||||
#include <cstdint> // int64_t
|
#include <cstdint> // int64_t
|
||||||
#include <map> // map
|
#include <map> // map
|
||||||
#include <string> // basic_string
|
#include <string> // basic_string
|
||||||
#include <type_traits> // enable_if, is_constructible
|
#include <type_traits> // decay, enable_if, is_arithmetic, is_constructible, is_integral, is_same
|
||||||
#include <unordered_map> // unordered_map
|
#include <unordered_map> // unordered_map
|
||||||
#include <vector> // vector
|
#include <vector> // vector
|
||||||
|
|
||||||
@@ -109,6 +109,11 @@ struct is_string_key : std::is_constructible<Key, const char*, std::size_t> {};
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
struct is_non_bool_arithmetic : conjunction<std::is_arithmetic<T>, negation<std::is_same<T, bool>>> {};
|
struct is_non_bool_arithmetic : conjunction<std::is_arithmetic<T>, negation<std::is_same<T, bool>>> {};
|
||||||
|
|
||||||
|
/// the default values of value() other than C strings, which have their own
|
||||||
|
/// overload (returning string_t)
|
||||||
|
template<typename T>
|
||||||
|
struct is_non_c_string_default : negation<std::is_same<typename std::decay<T>::type, const char*>> {};
|
||||||
|
|
||||||
/// whether View::get<T>() converts to T without materialize(); get_to()
|
/// whether View::get<T>() converts to T without materialize(); get_to()
|
||||||
/// assigns these, and passes the others to from_json
|
/// assigns these, and passes the others to from_json
|
||||||
template<typename T, typename BasicJsonType, typename View>
|
template<typename T, typename BasicJsonType, typename View>
|
||||||
|
|||||||
@@ -365,7 +365,7 @@ class basic_json_view
|
|||||||
/// the member with this key converted to T, or the default value if there
|
/// the member with this key converted to T, or the default value if there
|
||||||
/// is no such member (the first one, should the key occur more than
|
/// is no such member (the first one, should the key occur more than
|
||||||
/// once). Throws type_error.306 if this is not an object.
|
/// once). Throws type_error.306 if this is not an object.
|
||||||
template<typename T, typename std::enable_if<detail::negation<std::is_same<typename std::decay<T>::type, const char*>>::value, int>::type = 0>
|
template<typename T, typename std::enable_if<detail::view::is_non_c_string_default<T>::value, int>::type = 0>
|
||||||
T value(string_view_t key, const T& default_value) const
|
T value(string_view_t key, const T& default_value) const
|
||||||
{
|
{
|
||||||
if (NLOHMANN_VIEW_UNLIKELY(!is_object()))
|
if (NLOHMANN_VIEW_UNLIKELY(!is_object()))
|
||||||
@@ -384,7 +384,7 @@ class basic_json_view
|
|||||||
/// the value a JSON pointer refers to converted to T, or the default
|
/// the value a JSON pointer refers to converted to T, or the default
|
||||||
/// value if the pointer cannot be resolved. Throws type_error.306 if this
|
/// value if the pointer cannot be resolved. Throws type_error.306 if this
|
||||||
/// is neither an object nor an array.
|
/// is neither an object nor an array.
|
||||||
template<typename T, typename std::enable_if<detail::negation<std::is_same<typename std::decay<T>::type, const char*>>::value, int>::type = 0>
|
template<typename T, typename std::enable_if<detail::view::is_non_c_string_default<T>::value, int>::type = 0>
|
||||||
T value(const json_pointer& ptr, const T& default_value) const
|
T value(const json_pointer& ptr, const T& default_value) const
|
||||||
{
|
{
|
||||||
if (NLOHMANN_VIEW_UNLIKELY(!is_structured()))
|
if (NLOHMANN_VIEW_UNLIKELY(!is_structured()))
|
||||||
|
|||||||
Reference in new issue
Block a user