mirror of
https://github.com/nlohmann/json.git
synced 2026-09-06 00:08:00 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ae6f737976 |
@@ -4129,6 +4129,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
||||
/// @brief check if the input is valid JSON
|
||||
/// @sa https://json.nlohmann.me/api/basic_json/accept/
|
||||
template<typename InputType>
|
||||
JSON_HEDLEY_WARN_UNUSED_RESULT
|
||||
static bool accept(InputType&& i,
|
||||
const bool ignore_comments = false,
|
||||
const bool ignore_trailing_commas = false)
|
||||
@@ -4140,6 +4141,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
||||
/// @sa https://json.nlohmann.me/api/basic_json/accept/
|
||||
template<typename IteratorType, typename SentinelType = IteratorType,
|
||||
detail::enable_if_t<detail::can_compare_ne<IteratorType, SentinelType>::value, int> = 0>
|
||||
JSON_HEDLEY_WARN_UNUSED_RESULT
|
||||
static bool accept(IteratorType first, SentinelType last,
|
||||
const bool ignore_comments = false,
|
||||
const bool ignore_trailing_commas = false)
|
||||
|
||||
@@ -25557,6 +25557,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
||||
/// @brief check if the input is valid JSON
|
||||
/// @sa https://json.nlohmann.me/api/basic_json/accept/
|
||||
template<typename InputType>
|
||||
JSON_HEDLEY_WARN_UNUSED_RESULT
|
||||
static bool accept(InputType&& i,
|
||||
const bool ignore_comments = false,
|
||||
const bool ignore_trailing_commas = false)
|
||||
@@ -25568,6 +25569,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
||||
/// @sa https://json.nlohmann.me/api/basic_json/accept/
|
||||
template<typename IteratorType, typename SentinelType = IteratorType,
|
||||
detail::enable_if_t<detail::can_compare_ne<IteratorType, SentinelType>::value, int> = 0>
|
||||
JSON_HEDLEY_WARN_UNUSED_RESULT
|
||||
static bool accept(IteratorType first, SentinelType last,
|
||||
const bool ignore_comments = false,
|
||||
const bool ignore_trailing_commas = false)
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
// __ _____ _____ _____
|
||||
// __| | __| | | | 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,6 +862,22 @@ TEST_CASE("items()")
|
||||
|
||||
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")
|
||||
|
||||
@@ -30,6 +30,10 @@ using nlohmann::json;
|
||||
#include <cstdio>
|
||||
#include "make_test_data_available.hpp"
|
||||
|
||||
#ifdef JSON_HAS_CPP_17
|
||||
#include <variant>
|
||||
#endif
|
||||
|
||||
#include "fifo_map.hpp"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
|
||||
Reference in New Issue
Block a user