Skip to content

Commit

Permalink
Improve basic_json ctors
Browse files Browse the repository at this point in the history
  • Loading branch information
danielaparker committed Oct 21, 2024
1 parent c74713b commit 270f467
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 27 deletions.
54 changes: 27 additions & 27 deletions include/jsoncons/basic_json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3024,12 +3024,12 @@ namespace jsoncons {
construct<empty_object_storage>(semantic_tag::none);
}

explicit basic_json(const Allocator& alloc)
explicit basic_json(const allocator_type& alloc)
{
construct<object_storage>(object(alloc), semantic_tag::none);
}

basic_json(semantic_tag tag, const Allocator& alloc)
basic_json(semantic_tag tag, const allocator_type& alloc)
{
construct<object_storage>(object(alloc), tag);
}
Expand All @@ -3044,7 +3044,7 @@ namespace jsoncons {
uninitialized_copy(other);
}

basic_json(const basic_json& other, const Allocator& alloc)
basic_json(const basic_json& other, const allocator_type& alloc)
{
uninitialized_copy_a(other,alloc);
}
Expand All @@ -3054,20 +3054,20 @@ namespace jsoncons {
uninitialized_move(std::move(other));
}

template <typename U = Allocator>
basic_json(basic_json&& other, const Allocator& alloc) noexcept
template <typename U = allocator_type>
basic_json(basic_json&& other, const allocator_type& alloc) noexcept
{
uninitialized_move_a(extension_traits::is_stateless<U>{}, std::move(other), alloc);
}

explicit basic_json(json_object_arg_t,
semantic_tag tag,
const Allocator& alloc = Allocator())
const allocator_type& alloc = allocator_type())
{
construct<object_storage>(object(alloc), tag);
}

explicit basic_json(json_object_arg_t, const Allocator& alloc = Allocator())
explicit basic_json(json_object_arg_t, const allocator_type& alloc = allocator_type())
{
construct<object_storage>(object(alloc), semantic_tag::none);
}
Expand All @@ -3076,27 +3076,27 @@ namespace jsoncons {
basic_json(json_object_arg_t,
InputIt first, InputIt last,
semantic_tag tag = semantic_tag::none,
const Allocator& alloc = Allocator())
const allocator_type& alloc = allocator_type())
{
construct<object_storage>(object(first,last,alloc), 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())
const allocator_type& alloc = allocator_type())
{
construct<object_storage>(object(init,alloc), tag);
}

explicit basic_json(json_array_arg_t, const Allocator& alloc = Allocator())
explicit basic_json(json_array_arg_t, const allocator_type& alloc = allocator_type())
{
construct<array_storage>(array(alloc), semantic_tag::none);
}

explicit basic_json(json_array_arg_t,
semantic_tag tag,
const Allocator& alloc = Allocator())
const allocator_type& alloc = allocator_type())
{
construct<array_storage>(array(alloc), tag);
}
Expand All @@ -3105,15 +3105,15 @@ namespace jsoncons {
basic_json(json_array_arg_t,
InputIt first, InputIt last,
semantic_tag tag = semantic_tag::none,
const Allocator& alloc = Allocator())
const allocator_type& alloc = allocator_type())
{
construct<array_storage>(array(first,last,alloc), tag);
}

basic_json(json_array_arg_t,
std::initializer_list<basic_json> init,
semantic_tag tag = semantic_tag::none,
const Allocator& alloc = Allocator())
const allocator_type& alloc = allocator_type())
{
construct<array_storage>(array(init,alloc), tag);
}
Expand Down Expand Up @@ -3159,7 +3159,7 @@ namespace jsoncons {

template <typename T,
class = typename std::enable_if<!is_proxy_of<T,basic_json>::value && !extension_traits::is_basic_json<T>::value>::type>
basic_json(const T& val, const Allocator& alloc)
basic_json(const T& val, const allocator_type& alloc)
: basic_json(json_type_traits<basic_json,T>::to_json(val,alloc))
{
}
Expand Down Expand Up @@ -3194,7 +3194,7 @@ namespace jsoncons {
{
}

basic_json(const char_type* s, const Allocator& alloc)
basic_json(const char_type* s, const allocator_type& alloc)
: basic_json(s, char_traits_type::length(s), semantic_tag::none, alloc)
{
}
Expand All @@ -3211,7 +3211,7 @@ namespace jsoncons {
}
}

basic_json(const char_type* s, std::size_t length, semantic_tag tag, const Allocator& alloc)
basic_json(const char_type* s, std::size_t length, semantic_tag tag, const allocator_type& alloc)
{
if (length <= short_string_storage::max_length)
{
Expand Down Expand Up @@ -3251,14 +3251,14 @@ namespace jsoncons {
}

template <typename IntegerType>
basic_json(IntegerType val, semantic_tag tag, Allocator,
basic_json(IntegerType val, semantic_tag tag, allocator_type,
typename std::enable_if<extension_traits::is_unsigned_integer<IntegerType>::value && sizeof(IntegerType) <= sizeof(uint64_t), int>::type = 0)
{
construct<uint64_storage>(val, tag);
}

template <typename IntegerType>
basic_json(IntegerType val, semantic_tag, Allocator alloc = Allocator(),
basic_json(IntegerType val, semantic_tag, const allocator_type& alloc = allocator_type(),
typename std::enable_if<extension_traits::is_unsigned_integer<IntegerType>::value && sizeof(uint64_t) < sizeof(IntegerType), int>::type = 0)
{
std::basic_string<CharT> s;
Expand All @@ -3281,14 +3281,14 @@ namespace jsoncons {
}

template <typename IntegerType>
basic_json(IntegerType val, semantic_tag tag, Allocator,
basic_json(IntegerType val, semantic_tag tag, allocator_type,
typename std::enable_if<extension_traits::is_signed_integer<IntegerType>::value && sizeof(IntegerType) <= sizeof(int64_t),int>::type = 0)
{
construct<int64_storage>(val, tag);
}

template <typename IntegerType>
basic_json(IntegerType val, semantic_tag, Allocator alloc = Allocator(),
basic_json(IntegerType val, semantic_tag, const allocator_type& alloc = allocator_type(),
typename std::enable_if<extension_traits::is_signed_integer<IntegerType>::value && sizeof(int64_t) < sizeof(IntegerType),int>::type = 0)
{
std::basic_string<CharT> s;
Expand All @@ -3308,7 +3308,7 @@ namespace jsoncons {
construct<null_storage>(tag);
}

basic_json(null_type, semantic_tag tag, const Allocator&)
basic_json(null_type, semantic_tag tag, const allocator_type&)
{
construct<null_storage>(tag);
}
Expand All @@ -3318,7 +3318,7 @@ namespace jsoncons {
construct<bool_storage>(val,tag);
}

basic_json(bool val, semantic_tag tag, const Allocator&)
basic_json(bool val, semantic_tag tag, const allocator_type&)
{
construct<bool_storage>(val,tag);
}
Expand All @@ -3331,7 +3331,7 @@ namespace jsoncons {
template <typename Source>
basic_json(byte_string_arg_t, const Source& source,
semantic_tag tag = semantic_tag::none,
const Allocator& alloc = Allocator(),
const allocator_type& alloc = allocator_type(),
typename std::enable_if<extension_traits::is_byte_sequence<Source>::value,int>::type = 0)
{
auto bytes = jsoncons::span<const uint8_t>(reinterpret_cast<const uint8_t*>(source.data()), source.size());
Expand All @@ -3341,7 +3341,7 @@ namespace jsoncons {
template <typename Source>
basic_json(byte_string_arg_t, const Source& source,
uint64_t ext_tag,
const Allocator& alloc = Allocator(),
const allocator_type& alloc = allocator_type(),
typename std::enable_if<extension_traits::is_byte_sequence<Source>::value,int>::type = 0)
{
auto bytes = jsoncons::span<const uint8_t>(reinterpret_cast<const uint8_t*>(source.data()), source.size());
Expand Down Expand Up @@ -3648,7 +3648,7 @@ namespace jsoncons {
return allocator_type{};
}

template <typename U=Allocator>
template <typename U=allocator_type>
allocator_type get_allocator() const
{
switch (storage_kind())
Expand Down Expand Up @@ -3947,7 +3947,7 @@ namespace jsoncons {
}
}

template <typename U=Allocator>
template <typename U=allocator_type>
void create_object_implicitly()
{
create_object_implicitly(extension_traits::is_stateless<U>());
Expand Down Expand Up @@ -4972,7 +4972,7 @@ namespace jsoncons {
}

template <typename InputIterator>
basic_json(InputIterator first, InputIterator last, const Allocator& alloc = Allocator())
basic_json(InputIterator first, InputIterator last, const allocator_type& alloc = allocator_type())
: basic_json(json_array_arg,first,last,alloc)
{
}
Expand Down
1 change: 1 addition & 0 deletions test/corelib/src/ojson_object_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ TEST_CASE("ojson object erase with iterator")

CHECK(doc.size() == 1);
CHECK(doc.at("b") == 2);
CHECK(doc.at("b") == 2.0);
CHECK(doc["b"] == 2);
}

Expand Down

0 comments on commit 270f467

Please sign in to comment.