From 5c589dd138305e9073694dc9213fe839f9d9dce5 Mon Sep 17 00:00:00 2001 From: Martin Stump <11492152+globberwops@users.noreply.github.com> Date: Wed, 9 Dec 2020 11:37:01 +0100 Subject: [PATCH 1/8] Add MAIN_PROJECT check for test and install options --- CMakeLists.txt | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fa77a5aed2..93f7986a84 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,13 @@ cmake_minimum_required(VERSION 3.1) ## project(nlohmann_json VERSION 3.9.1 LANGUAGES CXX) +## +## MAIN_PROJECT CHECK +## +if (CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR) + set(MAIN_PROJECT ON) +endif() + ## ## INCLUDE ## @@ -21,8 +28,8 @@ if (POLICY CMP0077) cmake_policy(SET CMP0077 NEW) endif () -option(JSON_BuildTests "Build the unit tests when BUILD_TESTING is enabled." ON) -option(JSON_Install "Install CMake targets during install step." ON) +option(JSON_BuildTests "Build the unit tests when BUILD_TESTING is enabled." ${MAIN_PROJECT}) +option(JSON_Install "Install CMake targets during install step." ${MAIN_PROJECT}) option(JSON_MultipleHeaders "Use non-amalgamated version of the library." OFF) option(JSON_ImplicitConversions "Enable implicit conversions." ON) @@ -101,9 +108,8 @@ CONFIGURE_FILE( ## TESTS ## create and configure the unit test target ## -include(CTest) #adds option BUILD_TESTING (default ON) - -if(BUILD_TESTING AND JSON_BuildTests) +if (JSON_BuildTests) + include(CTest) #adds option BUILD_TESTING (default ON) enable_testing() add_subdirectory(test) endif() From 790508887e75a5be3f2ccc35a42ca474876bb86c Mon Sep 17 00:00:00 2001 From: Martin Stump <11492152+globberwops@users.noreply.github.com> Date: Wed, 9 Dec 2020 12:39:44 +0100 Subject: [PATCH 2/8] Set MAIN_PROJECT=OFF initially --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 93f7986a84..06761947bc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,7 @@ project(nlohmann_json VERSION 3.9.1 LANGUAGES CXX) ## ## MAIN_PROJECT CHECK ## +set(MAIN_PROJECT OFF) if (CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR) set(MAIN_PROJECT ON) endif() From ea759d03600b24af619daa7a3a1e277df50ca5b3 Mon Sep 17 00:00:00 2001 From: Martin Stump <11492152+globberwops@users.noreply.github.com> Date: Sun, 13 Dec 2020 20:34:51 +0100 Subject: [PATCH 3/8] Compare to CMAKE_CURRENT_SOURCE_DIR for main project check --- CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 06761947bc..7c4d8ad8c8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,9 +8,10 @@ project(nlohmann_json VERSION 3.9.1 LANGUAGES CXX) ## ## MAIN_PROJECT CHECK +## determine if nlohmann_json is built as a subproject (using add_subdirectory) or if it is the main project ## set(MAIN_PROJECT OFF) -if (CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR) +if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) set(MAIN_PROJECT ON) endif() From 85ffc85a298853028fba384724f6f483db38c1d2 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Mon, 14 Dec 2020 10:38:49 +0100 Subject: [PATCH 4/8] :art: amalgamate code --- include/nlohmann/detail/json_ref.hpp | 2 +- single_include/nlohmann/json.hpp | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/nlohmann/detail/json_ref.hpp b/include/nlohmann/detail/json_ref.hpp index 18e09f0519..26a4903828 100644 --- a/include/nlohmann/detail/json_ref.hpp +++ b/include/nlohmann/detail/json_ref.hpp @@ -57,7 +57,7 @@ class json_ref value_type const* operator->() const { - return &**this; + return &** this; } private: diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 835140b3dc..7e4dff2322 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -4515,15 +4515,15 @@ class byte_container_with_subtype : public BinaryType : container_type(std::move(b)) {} - byte_container_with_subtype(const container_type& b, std::uint8_t subtype) noexcept(noexcept(container_type(b))) + byte_container_with_subtype(const container_type& b, std::uint8_t subtype_) noexcept(noexcept(container_type(b))) : container_type(b) - , m_subtype(subtype) + , m_subtype(subtype_) , m_has_subtype(true) {} - byte_container_with_subtype(container_type&& b, std::uint8_t subtype) noexcept(noexcept(container_type(std::move(b)))) + byte_container_with_subtype(container_type&& b, std::uint8_t subtype_) noexcept(noexcept(container_type(std::move(b)))) : container_type(std::move(b)) - , m_subtype(subtype) + , m_subtype(subtype_) , m_has_subtype(true) {} @@ -4556,9 +4556,9 @@ class byte_container_with_subtype : public BinaryType @since version 3.8.0 */ - void set_subtype(std::uint8_t subtype) noexcept + void set_subtype(std::uint8_t subtype_) noexcept { - m_subtype = subtype; + m_subtype = subtype_; m_has_subtype = true; } @@ -12645,7 +12645,7 @@ class json_ref value_type const* operator->() const { - return &**this; + return &** this; } private: From 1771e9249fd09819d1f857d364e49b4178abd572 Mon Sep 17 00:00:00 2001 From: Martin Stump <11492152+globberwops@users.noreply.github.com> Date: Mon, 14 Dec 2020 10:59:38 +0100 Subject: [PATCH 5/8] Remove comment on CTest inclusion Co-authored-by: Niels Lohmann --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7c4d8ad8c8..44ede3e799 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -111,7 +111,7 @@ CONFIGURE_FILE( ## create and configure the unit test target ## if (JSON_BuildTests) - include(CTest) #adds option BUILD_TESTING (default ON) + include(CTest) enable_testing() add_subdirectory(test) endif() From 467986fe988dba45548c38c5aa680a47e3ad0579 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Mon, 14 Dec 2020 14:31:27 +0100 Subject: [PATCH 6/8] :recycle: do not unconditionally redefine C++14 constructs --- include/nlohmann/detail/meta/cpp_future.hpp | 24 ++++++++++++++++---- single_include/nlohmann/json.hpp | 25 +++++++++++++++++---- 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/include/nlohmann/detail/meta/cpp_future.hpp b/include/nlohmann/detail/meta/cpp_future.hpp index dd929ee142..4ba1a55714 100644 --- a/include/nlohmann/detail/meta/cpp_future.hpp +++ b/include/nlohmann/detail/meta/cpp_future.hpp @@ -2,19 +2,32 @@ #include // size_t #include // conditional, enable_if, false_type, integral_constant, is_constructible, is_integral, is_same, remove_cv, remove_reference, true_type +#include // index_sequence, make_index_sequence, index_sequence_for + +#include namespace nlohmann { namespace detail { -// alias templates to reduce boilerplate -template -using enable_if_t = typename std::enable_if::type; template using uncvref_t = typename std::remove_cv::type>::type; -// implementation of C++14 index_sequence and affiliates +#ifdef JSON_HAS_CPP_14 + +// the following utilities are natively available in C++14 +using std::enable_if_t; +using std::index_sequence; +using std::make_index_sequence; +using std::index_sequence_for; + +#else + +// alias templates to reduce boilerplate +template +using enable_if_t = typename std::enable_if::type; + // source: https://stackoverflow.com/a/32223343 template struct index_sequence @@ -45,6 +58,8 @@ template<> struct make_index_sequence<1> : index_sequence<0> {}; template using index_sequence_for = make_index_sequence; +#endif + // dispatch utility (taken from ranges-v3) template struct priority_tag : priority_tag < N - 1 > {}; template<> struct priority_tag<0> {}; @@ -58,5 +73,6 @@ struct static_const template constexpr T static_const::value; + } // namespace detail } // namespace nlohmann diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 7e4dff2322..87410d87d9 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -2736,19 +2736,33 @@ class other_error : public exception #include // size_t #include // conditional, enable_if, false_type, integral_constant, is_constructible, is_integral, is_same, remove_cv, remove_reference, true_type +#include // index_sequence, make_index_sequence, index_sequence_for + +// #include + namespace nlohmann { namespace detail { -// alias templates to reduce boilerplate -template -using enable_if_t = typename std::enable_if::type; template using uncvref_t = typename std::remove_cv::type>::type; -// implementation of C++14 index_sequence and affiliates +#ifdef JSON_HAS_CPP_14 + +// the following utilities are natively available in C++14 +using std::enable_if_t; +using std::index_sequence; +using std::make_index_sequence; +using std::index_sequence_for; + +#else + +// alias templates to reduce boilerplate +template +using enable_if_t = typename std::enable_if::type; + // source: https://stackoverflow.com/a/32223343 template struct index_sequence @@ -2779,6 +2793,8 @@ template<> struct make_index_sequence<1> : index_sequence<0> {}; template using index_sequence_for = make_index_sequence; +#endif + // dispatch utility (taken from ranges-v3) template struct priority_tag : priority_tag < N - 1 > {}; template<> struct priority_tag<0> {}; @@ -2792,6 +2808,7 @@ struct static_const template constexpr T static_const::value; + } // namespace detail } // namespace nlohmann From 94d177e09a574a4d02f5c994ca1a6b8c79791477 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Mon, 14 Dec 2020 14:58:59 +0100 Subject: [PATCH 7/8] :page_facing_up: clarify license --- include/nlohmann/detail/meta/type_traits.hpp | 5 +++-- single_include/nlohmann/json.hpp | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/include/nlohmann/detail/meta/type_traits.hpp b/include/nlohmann/detail/meta/type_traits.hpp index ac143becf5..56c15a3f66 100644 --- a/include/nlohmann/detail/meta/type_traits.hpp +++ b/include/nlohmann/detail/meta/type_traits.hpp @@ -168,7 +168,9 @@ struct is_iterator_traits> is_detected::value; }; -// source: https://stackoverflow.com/a/37193089/4116453 +// The following implementation of is_complete_type is taken from +// https://blogs.msdn.microsoft.com/vcblog/2015/12/02/partial-support-for-expression-sfinae-in-vs-2015-update-1/ +// and is written by Xiang Fan who agreed to using it in this library. template struct is_complete_type : std::false_type {}; @@ -186,7 +188,6 @@ struct is_compatible_object_type_impl < enable_if_t < is_detected::value&& is_detected::value >> { - using object_t = typename BasicJsonType::object_t; // macOS's is_constructible does not play well with nonesuch... diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 7e4dff2322..78679672d2 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -3174,7 +3174,9 @@ struct is_iterator_traits> is_detected::value; }; -// source: https://stackoverflow.com/a/37193089/4116453 +// The following implementation of is_complete_type is taken from +// https://blogs.msdn.microsoft.com/vcblog/2015/12/02/partial-support-for-expression-sfinae-in-vs-2015-update-1/ +// and is written by Xiang Fan who agreed to using it in this library. template struct is_complete_type : std::false_type {}; @@ -3192,7 +3194,6 @@ struct is_compatible_object_type_impl < enable_if_t < is_detected::value&& is_detected::value >> { - using object_t = typename BasicJsonType::object_t; // macOS's is_constructible does not play well with nonesuch... From 5cc5285fe83bd2f8d8abc6396535b2d2aff15e14 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Tue, 15 Dec 2020 22:15:36 +0100 Subject: [PATCH 8/8] :rotating_light: fix shadowing warning --- include/nlohmann/json.hpp | 12 ++++++------ single_include/nlohmann/json.hpp | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index cd56dafdc4..a726d1adf3 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -923,14 +923,14 @@ class basic_json AllocatorType alloc; using AllocatorTraits = std::allocator_traits>; - auto deleter = [&](T * object) + auto deleter = [&](T * obj) { - AllocatorTraits::deallocate(alloc, object, 1); + AllocatorTraits::deallocate(alloc, obj, 1); }; - std::unique_ptr object(AllocatorTraits::allocate(alloc, 1), deleter); - AllocatorTraits::construct(alloc, object.get(), std::forward(args)...); - JSON_ASSERT(object != nullptr); - return object.release(); + std::unique_ptr obj(AllocatorTraits::allocate(alloc, 1), deleter); + AllocatorTraits::construct(alloc, obj.get(), std::forward(args)...); + JSON_ASSERT(obj != nullptr); + return obj.release(); } //////////////////////// diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 7e4dff2322..6fa1849d85 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -17495,14 +17495,14 @@ class basic_json AllocatorType alloc; using AllocatorTraits = std::allocator_traits>; - auto deleter = [&](T * object) + auto deleter = [&](T * obj) { - AllocatorTraits::deallocate(alloc, object, 1); + AllocatorTraits::deallocate(alloc, obj, 1); }; - std::unique_ptr object(AllocatorTraits::allocate(alloc, 1), deleter); - AllocatorTraits::construct(alloc, object.get(), std::forward(args)...); - JSON_ASSERT(object != nullptr); - return object.release(); + std::unique_ptr obj(AllocatorTraits::allocate(alloc, 1), deleter); + AllocatorTraits::construct(alloc, obj.get(), std::forward(args)...); + JSON_ASSERT(obj != nullptr); + return obj.release(); } ////////////////////////