diff --git a/tests/src/unit-items-cpp17.cpp b/tests/src/unit-items-cpp17.cpp new file mode 100644 index 000000000..577dcea56 --- /dev/null +++ b/tests/src/unit-items-cpp17.cpp @@ -0,0 +1,42 @@ +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ (supporting code) +// | | |__ | | | | | | version 3.12.0 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013-2026 Niels Lohmann +// SPDX-License-Identifier: MIT + +// This file contains the C++17-only part of unit-items.cpp (structured +// bindings support for json::items()). It is kept in a separate +// translation unit so the (much larger) unit-items.cpp does not need to +// be compiled a second time just for this one SECTION. + +#include "doctest_compatibility.h" + +#include +using nlohmann::json; + +#ifdef JSON_HAS_CPP_17 +#include +#include + +TEST_CASE("items()") +{ + SECTION("object") + { + SECTION("structured bindings") + { + json j = { {"A", 1}, {"B", 2} }; + + std::map m; + + for (auto const&[key, value] : j.items()) + { + m.emplace(key, value); + } + + CHECK(j.get() == m); + } + } +} +#endif diff --git a/tests/src/unit-items.cpp b/tests/src/unit-items.cpp index fa8948447..81959db8d 100644 --- a/tests/src/unit-items.cpp +++ b/tests/src/unit-items.cpp @@ -862,22 +862,6 @@ TEST_CASE("items()") CHECK(counter == 3); } - -#ifdef JSON_HAS_CPP_17 - SECTION("structured bindings") - { - json j = { {"A", 1}, {"B", 2} }; - - std::map m; - - for (auto const&[key, value] : j.items()) - { - m.emplace(key, value); - } - - CHECK(j.get() == m); - } -#endif } SECTION("const object") diff --git a/tests/src/unit-regression1.cpp b/tests/src/unit-regression1.cpp index fdc3fdd05..0529f83dd 100644 --- a/tests/src/unit-regression1.cpp +++ b/tests/src/unit-regression1.cpp @@ -31,10 +31,6 @@ using nlohmann::json; #include "make_test_data_available.hpp" #include "test_utils.hpp" -#ifdef JSON_HAS_CPP_17 - #include -#endif - #include "fifo_map.hpp" /////////////////////////////////////////////////////////////////////