Add helper types to make it easier to create a basic_json type with modified template parameters

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
barcode
2026-10-04 18:00:36 +02:00
committed by Niels Lohmann
parent 8c1f60a45e
commit c7a0d59e16
7 changed files with 127 additions and 77 deletions
+3 -24
View File
@@ -48,14 +48,7 @@ TEST_CASE("bad_alloc")
SECTION("bad_alloc")
{
// create JSON type using the throwing allocator
using bad_json = nlohmann::basic_json<std::map,
std::vector,
std::string,
bool,
std::int64_t,
std::uint64_t,
double,
bad_allocator>;
using bad_json = nlohmann::json::with_changed_allocator_t<bad_allocator>;
// creating an object should throw
CHECK_THROWS_AS(bad_json(bad_json::value_t::object), std::bad_alloc&);
@@ -129,14 +122,7 @@ void my_allocator_clean_up(T* p)
TEST_CASE("controlled bad_alloc")
{
// create JSON type using the throwing allocator
using my_json = nlohmann::basic_json<std::map,
std::vector,
std::string,
bool,
std::int64_t,
std::uint64_t,
double,
my_allocator>;
using my_json = nlohmann::json::with_changed_allocator_t<my_allocator>;
SECTION("class json_value")
{
@@ -588,14 +574,7 @@ TEST_CASE("bad my_allocator::construct")
{
SECTION("my_allocator::construct doesn't forward")
{
using bad_alloc_json = nlohmann::basic_json<std::map,
std::vector,
std::string,
bool,
std::int64_t,
std::uint64_t,
double,
allocator_no_forward>;
using bad_alloc_json = nlohmann::json::with_changed_allocator_t<allocator_no_forward>;
bad_alloc_json j;
j["test"] = bad_alloc_json::array_t();