Skip to content

Commit

Permalink
Improve basic_json storage
Browse files Browse the repository at this point in the history
  • Loading branch information
danielaparker committed Oct 28, 2024
1 parent 4fc424b commit 2332059
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
13 changes: 9 additions & 4 deletions include/jsoncons/basic_json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3125,7 +3125,9 @@ namespace jsoncons {

explicit basic_json(json_object_arg_t, const Allocator& alloc = Allocator())
{
construct<object_storage>(object(alloc), semantic_tag::none);
//construct<object_storage>(object(alloc), semantic_tag::none);
auto ptr = create_ptr<object_storage>(alloc);
construct<object_storage>(ptr, semantic_tag::none);
}

template <typename InputIt>
Expand All @@ -3134,20 +3136,23 @@ namespace jsoncons {
semantic_tag tag = semantic_tag::none,
const Allocator& alloc = Allocator())
{
construct<object_storage>(object(first,last,alloc), tag);
//construct<object_storage>(object(first,last,alloc), tag);
auto ptr = create_ptr<object_storage>(alloc, first, last);
construct<object_storage>(ptr, tag);
}

basic_json(json_object_arg_t,
std::initializer_list<std::pair<std::basic_string<char_type>,basic_json>> init,
semantic_tag tag = semantic_tag::none,
const Allocator& alloc = Allocator())
{
construct<object_storage>(object(init,alloc), tag);
//construct<object_storage>(object(init,alloc), tag);
auto ptr = create_ptr<object_storage>(alloc, init);
construct<object_storage>(ptr, tag);
}

explicit basic_json(json_array_arg_t, const Allocator& alloc = Allocator())
{
//construct<array_storage>(array(alloc), semantic_tag::none);
auto ptr = create_ptr<array_storage>(alloc);
construct<array_storage>(ptr, semantic_tag::none);
}
Expand Down
19 changes: 19 additions & 0 deletions test/corelib/src/json_constructor_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,25 @@ TEST_CASE("json constructor with scoped_allocator")
cust_json j3{std::move(j2), alloc2};
REQUIRE(alloc2 == j3.get_allocator());
}
/*
SECTION("iterator constructor")
{
std::map<std::string,double> m = {{"c",1},{"b",2},{"a",3}};
cust_json j1{jsoncons::json_object_arg, m.begin(), m.end(), semantic_tag::none, alloc1};
REQUIRE(alloc1 == j1.get_allocator());
REQUIRE(j1.size() == 3);
CHECK(j1.at("a") == 3);
CHECK(j1.at("b") == 2);
CHECK(j1.at("c") == 1);
cust_json j2{std::move(j1)};
REQUIRE(alloc1 == j2.get_allocator());
cust_json j3{std::move(j2), alloc2};
REQUIRE(alloc2 == j3.get_allocator());
}
*/
}

#endif // scoped_allocator
Expand Down

0 comments on commit 2332059

Please sign in to comment.