mirror of
https://github.com/nlohmann/json.git
synced 2026-09-06 16:27:59 +00:00
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4776b9091c | ||
|
|
fd0ca40ea6 |
@@ -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 <https://nlohmann.me>
|
||||||
|
// 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 <nlohmann/json.hpp>
|
||||||
|
using nlohmann::json;
|
||||||
|
|
||||||
|
#ifdef JSON_HAS_CPP_17
|
||||||
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
TEST_CASE("items()")
|
||||||
|
{
|
||||||
|
SECTION("object")
|
||||||
|
{
|
||||||
|
SECTION("structured bindings")
|
||||||
|
{
|
||||||
|
json j = { {"A", 1}, {"B", 2} };
|
||||||
|
|
||||||
|
std::map<std::string, int> m;
|
||||||
|
|
||||||
|
for (auto const&[key, value] : j.items())
|
||||||
|
{
|
||||||
|
m.emplace(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
CHECK(j.get<decltype(m)>() == m);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@@ -862,22 +862,6 @@ TEST_CASE("items()")
|
|||||||
|
|
||||||
CHECK(counter == 3);
|
CHECK(counter == 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef JSON_HAS_CPP_17
|
|
||||||
SECTION("structured bindings")
|
|
||||||
{
|
|
||||||
json j = { {"A", 1}, {"B", 2} };
|
|
||||||
|
|
||||||
std::map<std::string, int> m;
|
|
||||||
|
|
||||||
for (auto const&[key, value] : j.items())
|
|
||||||
{
|
|
||||||
m.emplace(key, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
CHECK(j.get<decltype(m)>() == m);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("const object")
|
SECTION("const object")
|
||||||
|
|||||||
@@ -30,10 +30,6 @@ using nlohmann::json;
|
|||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include "make_test_data_available.hpp"
|
#include "make_test_data_available.hpp"
|
||||||
|
|
||||||
#ifdef JSON_HAS_CPP_17
|
|
||||||
#include <variant>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "fifo_map.hpp"
|
#include "fifo_map.hpp"
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////
|
||||||
|
|||||||
Reference in New Issue
Block a user