Skip to content

Commit

Permalink
Merge pull request #1741 from tete17/Fix-SFINAE
Browse files Browse the repository at this point in the history
Fix and add test's for SFINAE problem
  • Loading branch information
nlohmann committed Sep 16, 2019
2 parents 06ccd43 + e26a290 commit 771d5da
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion include/nlohmann/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4010,7 +4010,7 @@ class basic_json
@since version 3.6.0
*/
template<typename KeyT, typename std::enable_if<
not std::is_same<KeyT, json_pointer>::value, int>::type = 0>
not std::is_same<typename std::decay<KeyT>::type, json_pointer>::value, int>::type = 0>
bool contains(KeyT && key) const
{
return is_object() and m_value.object->find(std::forward<KeyT>(key)) != m_value.object->end();
Expand Down
2 changes: 1 addition & 1 deletion single_include/nlohmann/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18445,7 +18445,7 @@ class basic_json
@since version 3.6.0
*/
template<typename KeyT, typename std::enable_if<
not std::is_same<KeyT, json_pointer>::value, int>::type = 0>
not std::is_same<typename std::decay<KeyT>::type, json_pointer>::value, int>::type = 0>
bool contains(KeyT && key) const
{
return is_object() and m_value.object->find(std::forward<KeyT>(key)) != m_value.object->end();
Expand Down
11 changes: 11 additions & 0 deletions test/src/unit-regression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 771d5da

Please sign in to comment.