diff --git a/src/json.hpp b/src/json.hpp index 124a794f..c40691a5 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -107,7 +107,14 @@ SOFTWARE. */ namespace nlohmann { +// TODO update this doc +/*! +@brief unnamed namespace with internal helper functions +@since version 1.0.0 +*/ +namespace detail +{ /////////////////////////// // JSON type enumeration // /////////////////////////// @@ -147,6 +154,45 @@ enum class value_t : uint8_t discarded ///< discarded by the the parser callback function }; +////////////////////////////////////////// +// lexicographical comparison operators // +////////////////////////////////////////// + +/// @name lexicographical comparison operators +/// @{ +/*! +@brief comparison operator for JSON types + +Returns an ordering that is similar to Python: +- order: null < boolean < number < object < array < string +- furthermore, each type is not smaller than itself + +@since version 1.0.0 +*/ +inline bool operator<(const value_t lhs, const value_t rhs) noexcept +{ + static constexpr std::array order = {{ + 0, // null + 3, // object + 4, // array + 5, // string + 1, // boolean + 2, // integer + 2, // unsigned + 2, // float + } + }; + + // discarded values are not comparable + if (lhs == value_t::discarded or rhs == value_t::discarded) + { + return false; + } + + return order[static_cast(lhs)] < + order[static_cast(rhs)]; +} + // alias templates to reduce boilerplate template using enable_if_t = typename std::enable_if::type; @@ -160,14 +206,6 @@ using is_unscoped_enum = std::integral_constant::value and std::is_enum::value>; -// TODO update this doc -/*! -@brief unnamed namespace with internal helper functions -@since version 1.0.0 -*/ - -namespace detail -{ // Implementation of 2 C++17 constructs: conjunction, negation. // This is needed to avoid evaluating all the traits in a condition // @@ -967,14 +1005,14 @@ template < class basic_json { private: - template <::nlohmann::value_t> friend struct detail::external_constructor; + template friend struct detail::external_constructor; /// workaround type for MSVC using basic_json_t = basic_json; public: - using value_t = ::nlohmann::value_t; + using value_t = detail::value_t; // forward declarations template class iter_impl; template class json_reverse_iterator; @@ -1866,13 +1904,13 @@ class basic_json @since version 2.1.0 */ - template , - enable_if_t::value and - not std::is_same::value and - not detail::is_basic_json_nested_type< - basic_json_t, U>::value and - detail::has_to_json::value, - int> = 0> + template , + detail::enable_if_t::value and + not std::is_same::value and + not detail::is_basic_json_nested_type< + basic_json_t, U>::value and + detail::has_to_json::value, + int> = 0> basic_json(T && val) noexcept(noexcept(JSONSerializer::to_json( std::declval(), std::forward(val)))) { @@ -3036,7 +3074,7 @@ class basic_json @since version 2.1.0 */ template ::value, int> = 0> + detail::enable_if_t::value, int> = 0> basic_json get() const { return *this; @@ -3059,8 +3097,8 @@ class basic_json */ template < typename T, - typename U = uncvref_t, - enable_if_t < + typename U = detail::uncvref_t, + detail::enable_if_t < not std::is_same::value and detail::has_from_json::value and not detail::has_non_default_from_json>::value and - detail::has_non_default_from_json>::value, - int> = 0 > - uncvref_t get() const noexcept(noexcept(JSONSerializer::from_json(std::declval()))) + detail::enable_if_t>::value and + detail::has_non_default_from_json>::value, + int> = 0 > + detail::uncvref_t get() const noexcept(noexcept(JSONSerializer::from_json(std::declval()))) { return JSONSerializer::from_json(*this); } @@ -12401,45 +12439,6 @@ basic_json_parser_66: /// @} }; -////////////////////////////////////////// -// lexicographical comparison operators // -////////////////////////////////////////// - -/// @name lexicographical comparison operators -/// @{ -/*! -@brief comparison operator for JSON types - -Returns an ordering that is similar to Python: -- order: null < boolean < number < object < array < string -- furthermore, each type is not smaller than itself - -@since version 1.0.0 -*/ -inline bool operator<(const value_t lhs, const value_t rhs) noexcept -{ - static constexpr std::array order = {{ - 0, // null - 3, // object - 4, // array - 5, // string - 1, // boolean - 2, // integer - 2, // unsigned - 2, // float - } - }; - - // discarded values are not comparable - if (lhs == value_t::discarded or rhs == value_t::discarded) - { - return false; - } - - return order[static_cast(lhs)] < - order[static_cast(rhs)]; -} - ///////////// // presets // ///////////// diff --git a/src/json.hpp.re2c b/src/json.hpp.re2c index 7ba1cc85..e3fee848 100644 --- a/src/json.hpp.re2c +++ b/src/json.hpp.re2c @@ -107,7 +107,14 @@ SOFTWARE. */ namespace nlohmann { +// TODO update this doc +/*! +@brief unnamed namespace with internal helper functions +@since version 1.0.0 +*/ +namespace detail +{ /////////////////////////// // JSON type enumeration // /////////////////////////// @@ -147,6 +154,45 @@ enum class value_t : uint8_t discarded ///< discarded by the the parser callback function }; +////////////////////////////////////////// +// lexicographical comparison operators // +////////////////////////////////////////// + +/// @name lexicographical comparison operators +/// @{ +/*! +@brief comparison operator for JSON types + +Returns an ordering that is similar to Python: +- order: null < boolean < number < object < array < string +- furthermore, each type is not smaller than itself + +@since version 1.0.0 +*/ +inline bool operator<(const value_t lhs, const value_t rhs) noexcept +{ + static constexpr std::array order = {{ + 0, // null + 3, // object + 4, // array + 5, // string + 1, // boolean + 2, // integer + 2, // unsigned + 2, // float + } + }; + + // discarded values are not comparable + if (lhs == value_t::discarded or rhs == value_t::discarded) + { + return false; + } + + return order[static_cast(lhs)] < + order[static_cast(rhs)]; +} + // alias templates to reduce boilerplate template using enable_if_t = typename std::enable_if::type; @@ -160,14 +206,6 @@ using is_unscoped_enum = std::integral_constant::value and std::is_enum::value>; -// TODO update this doc -/*! -@brief unnamed namespace with internal helper functions -@since version 1.0.0 -*/ - -namespace detail -{ // Implementation of 2 C++17 constructs: conjunction, negation. // This is needed to avoid evaluating all the traits in a condition // @@ -967,14 +1005,14 @@ template < class basic_json { private: - template <::nlohmann::value_t> friend struct detail::external_constructor; + template friend struct detail::external_constructor; /// workaround type for MSVC using basic_json_t = basic_json; public: - using value_t = ::nlohmann::value_t; + using value_t = detail::value_t; // forward declarations template class iter_impl; template class json_reverse_iterator; @@ -1866,13 +1904,13 @@ class basic_json @since version 2.1.0 */ - template , - enable_if_t::value and - not std::is_same::value and - not detail::is_basic_json_nested_type< - basic_json_t, U>::value and - detail::has_to_json::value, - int> = 0> + template , + detail::enable_if_t::value and + not std::is_same::value and + not detail::is_basic_json_nested_type< + basic_json_t, U>::value and + detail::has_to_json::value, + int> = 0> basic_json(T && val) noexcept(noexcept(JSONSerializer::to_json( std::declval(), std::forward(val)))) { @@ -3036,7 +3074,7 @@ class basic_json @since version 2.1.0 */ template ::value, int> = 0> + detail::enable_if_t::value, int> = 0> basic_json get() const { return *this; @@ -3059,8 +3097,8 @@ class basic_json */ template < typename T, - typename U = uncvref_t, - enable_if_t < + typename U = detail::uncvref_t, + detail::enable_if_t < not std::is_same::value and detail::has_from_json::value and not detail::has_non_default_from_json>::value and - detail::has_non_default_from_json>::value, - int> = 0 > - uncvref_t get() const noexcept(noexcept(JSONSerializer::from_json(std::declval()))) + detail::enable_if_t>::value and + detail::has_non_default_from_json>::value, + int> = 0 > + detail::uncvref_t get() const noexcept(noexcept(JSONSerializer::from_json(std::declval()))) { return JSONSerializer::from_json(*this); } @@ -11551,45 +11589,6 @@ class basic_json /// @} }; -////////////////////////////////////////// -// lexicographical comparison operators // -////////////////////////////////////////// - -/// @name lexicographical comparison operators -/// @{ -/*! -@brief comparison operator for JSON types - -Returns an ordering that is similar to Python: -- order: null < boolean < number < object < array < string -- furthermore, each type is not smaller than itself - -@since version 1.0.0 -*/ -inline bool operator<(const value_t lhs, const value_t rhs) noexcept -{ - static constexpr std::array order = {{ - 0, // null - 3, // object - 4, // array - 5, // string - 1, // boolean - 2, // integer - 2, // unsigned - 2, // float - } - }; - - // discarded values are not comparable - if (lhs == value_t::discarded or rhs == value_t::discarded) - { - return false; - } - - return order[static_cast(lhs)] < - order[static_cast(rhs)]; -} - ///////////// // presets // /////////////