From e26a2904fcdcd53e514c85f1990e2065393f5e7c Mon Sep 17 00:00:00 2001 From: Miguel Sacristan Date: Sat, 7 Sep 2019 17:36:24 +0200 Subject: [PATCH] Fix and add test's for SFINAE problem --- include/nlohmann/json.hpp | 2 +- single_include/nlohmann/json.hpp | 2 +- test/src/unit-regression.cpp | 11 +++++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index f5210a6b..895a8ec1 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -4010,7 +4010,7 @@ class basic_json @since version 3.6.0 */ template::value, int>::type = 0> + not std::is_same::type, json_pointer>::value, int>::type = 0> bool contains(KeyT && key) const { return is_object() and m_value.object->find(std::forward(key)) != m_value.object->end(); diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 31702a9f..bdd3642f 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -18445,7 +18445,7 @@ class basic_json @since version 3.6.0 */ template::value, int>::type = 0> + not std::is_same::type, json_pointer>::value, int>::type = 0> bool contains(KeyT && key) const { return is_object() and m_value.object->find(std::forward(key)) != m_value.object->end(); diff --git a/test/src/unit-regression.cpp b/test/src/unit-regression.cpp index c9e8b0d7..e0c5b20a 100644 --- a/test/src/unit-regression.cpp +++ b/test/src/unit-regression.cpp @@ -1809,6 +1809,17 @@ TEST_CASE("regression tests") json j = smallest; CHECK(j.dump() == std::to_string(smallest)); } + + SECTION("issue #1727 - Contains with non-const lvalue json_pointer picks the wrong overload") + { + json j = {{"root", {{"settings", {{"logging", true}}}}}}; + + auto jptr1 = "/root/settings/logging"_json_pointer; + auto jptr2 = json::json_pointer{"/root/settings/logging"}; + + CHECK(j.contains(jptr1)); + CHECK(j.contains(jptr2)); + } } #if not defined(JSON_NOEXCEPTION)