mirror of
https://github.com/nlohmann/json.git
synced 2026-03-23 09:22:44 +00:00
Allow allocators for output_vector_adapter (#2989)
* ♻️ allow allocators for vectors * ✅ add regression tests
This commit is contained in:
@@ -181,6 +181,13 @@ class sax_no_exception : public nlohmann::detail::json_sax_dom_parser<json>
|
||||
|
||||
std::string* sax_no_exception::error_string = nullptr;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
// for #2982
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class T>
|
||||
class my_allocator : public std::allocator<T>
|
||||
{};
|
||||
|
||||
TEST_CASE("regression tests 2")
|
||||
{
|
||||
@@ -679,6 +686,15 @@ TEST_CASE("regression tests 2")
|
||||
test3[json::json_pointer(p)] = json::object();
|
||||
CHECK(test3.dump() == "{\"/root\":{}}");
|
||||
}
|
||||
|
||||
SECTION("issue #2982 - to_{binary format} does not provide a mechanism for specifying a custom allocator for the returned type")
|
||||
{
|
||||
std::vector<std::uint8_t, my_allocator<std::uint8_t>> my_vector;
|
||||
json j = {1, 2, 3, 4};
|
||||
json::to_cbor(j, my_vector);
|
||||
json k = json::from_cbor(my_vector);
|
||||
CHECK(j == k);
|
||||
}
|
||||
}
|
||||
|
||||
DOCTEST_CLANG_SUPPRESS_WARNING_POP
|
||||
|
||||
Reference in New Issue
Block a user