|
| 1 | +From ec955f08b47ab7cb81f6e4a4c3e7b331ddf50f71 Mon Sep 17 00:00:00 2001 |
| 2 | +From: =?UTF-8?q?Art=C3=B6m=20Bakri=20Al-Sarmini?= < [email protected]> |
| 3 | +Date: Sun, 12 Apr 2020 22:32:39 +0300 |
| 4 | +Subject: [PATCH] Templatize basic_json ctor from json_ref |
| 5 | + |
| 6 | +Upstream-Status: Backport [https://github.com/nlohmann/json/commit/ec955f08b47ab7cb81f6e4a4c3e7b331ddf50f71] |
| 7 | +Signed-off-by: Andrew Geissler < [email protected]> |
| 8 | + |
| 9 | +--- |
| 10 | + include/nlohmann/detail/meta/type_traits.hpp | 13 ++++++++++++ |
| 11 | + include/nlohmann/json.hpp | 8 ++++---- |
| 12 | + single_include/nlohmann/json.hpp | 21 ++++++++++++++++---- |
| 13 | + 3 files changed, 34 insertions(+), 8 deletions(-) |
| 14 | + |
| 15 | +diff --git a/include/nlohmann/detail/meta/type_traits.hpp b/include/nlohmann/detail/meta/type_traits.hpp |
| 16 | +index 280f6953..dd0b3084 100644 |
| 17 | +--- a/include/nlohmann/detail/meta/type_traits.hpp |
| 18 | ++++ b/include/nlohmann/detail/meta/type_traits.hpp |
| 19 | +@@ -41,6 +41,19 @@ template<typename> struct is_basic_json : std::false_type {}; |
| 20 | + NLOHMANN_BASIC_JSON_TPL_DECLARATION |
| 21 | + struct is_basic_json<NLOHMANN_BASIC_JSON_TPL> : std::true_type {}; |
| 22 | + |
| 23 | ++////////////////////// |
| 24 | ++// jspn_ref helpers // |
| 25 | ++////////////////////// |
| 26 | ++ |
| 27 | ++template <typename> |
| 28 | ++class json_ref; |
| 29 | ++ |
| 30 | ++template<typename> |
| 31 | ++struct is_json_ref : std::false_type {}; |
| 32 | ++ |
| 33 | ++template <typename T> |
| 34 | ++struct is_json_ref<json_ref<T>> : std::true_type {}; |
| 35 | ++ |
| 36 | + ////////////////////////// |
| 37 | + // aliases for detected // |
| 38 | + ////////////////////////// |
| 39 | +diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp |
| 40 | +index 336d69fe..0598efc8 100644 |
| 41 | +--- a/include/nlohmann/json.hpp |
| 42 | ++++ b/include/nlohmann/json.hpp |
| 43 | +@@ -1773,10 +1773,10 @@ class basic_json |
| 44 | + // other constructors and destructor // |
| 45 | + /////////////////////////////////////// |
| 46 | + |
| 47 | +- /// @private |
| 48 | +- basic_json(const detail::json_ref<basic_json>& ref) |
| 49 | +- : basic_json(ref.moved_or_copied()) |
| 50 | +- {} |
| 51 | ++ template <typename JsonRef, |
| 52 | ++ detail::enable_if_t<detail::conjunction<detail::is_json_ref<JsonRef>, |
| 53 | ++ std::is_same<typename JsonRef::value_type, basic_json>>::value, int> = 0 > |
| 54 | ++ basic_json(const JsonRef& ref) : basic_json(ref.moved_or_copied()) {} |
| 55 | + |
| 56 | + /*! |
| 57 | + @brief copy constructor |
| 58 | +diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp |
| 59 | +index 09464f3b..8927180e 100644 |
| 60 | +--- a/single_include/nlohmann/json.hpp |
| 61 | ++++ b/single_include/nlohmann/json.hpp |
| 62 | +@@ -2794,6 +2794,19 @@ template<typename> struct is_basic_json : std::false_type {}; |
| 63 | + NLOHMANN_BASIC_JSON_TPL_DECLARATION |
| 64 | + struct is_basic_json<NLOHMANN_BASIC_JSON_TPL> : std::true_type {}; |
| 65 | + |
| 66 | ++////////////////////// |
| 67 | ++// jspn_ref helpers // |
| 68 | ++////////////////////// |
| 69 | ++ |
| 70 | ++template <typename> |
| 71 | ++class json_ref; |
| 72 | ++ |
| 73 | ++template<typename> |
| 74 | ++struct is_json_ref : std::false_type {}; |
| 75 | ++ |
| 76 | ++template <typename T> |
| 77 | ++struct is_json_ref<json_ref<T>> : std::true_type {}; |
| 78 | ++ |
| 79 | + ////////////////////////// |
| 80 | + // aliases for detected // |
| 81 | + ////////////////////////// |
| 82 | +@@ -16632,10 +16645,10 @@ class basic_json |
| 83 | + // other constructors and destructor // |
| 84 | + /////////////////////////////////////// |
| 85 | + |
| 86 | +- /// @private |
| 87 | +- basic_json(const detail::json_ref<basic_json>& ref) |
| 88 | +- : basic_json(ref.moved_or_copied()) |
| 89 | +- {} |
| 90 | ++ template <typename JsonRef, |
| 91 | ++ detail::enable_if_t<detail::conjunction<detail::is_json_ref<JsonRef>, |
| 92 | ++ std::is_same<typename JsonRef::value_type, basic_json>>::value, int> = 0 > |
| 93 | ++ basic_json(const JsonRef& ref) : basic_json(ref.moved_or_copied()) {} |
| 94 | + |
| 95 | + /*! |
| 96 | + @brief copy constructor |
| 97 | +-- |
| 98 | +2.21.0 (Apple Git-122) |
| 99 | + |
0 commit comments