6 #ifndef METALL_JSON_VALUE_HPP
7 #define METALL_JSON_VALUE_HPP
11 #include <string_view>
13 #include <type_traits>
27 template <
typename allocator_type,
typename other_value_type>
29 const other_value_type &other_value) noexcept {
30 if (other_value.is_null()) {
32 }
else if (other_value.is_bool()) {
34 }
else if (other_value.is_int64()) {
39 return (other_value.as_int64() < 0)
42 static_cast<std::uint64_t
>(other_value.as_int64());
45 }
else if (other_value.is_uint64()) {
53 other_value.as_uint64();
56 }
else if (other_value.is_double()) {
58 }
else if (other_value.is_object()) {
60 }
else if (other_value.is_array()) {
62 }
else if (other_value.is_string()) {
65 const auto &other_srt = other_value.as_string();
66 return str.compare(other_srt.c_str()) == 0;
78 template <
typename Alloc = std::allocator<std::
byte>>
80 template <
typename Alloc>
87 typename std::allocator_traits<
93 using internal_data_type =
94 std::variant<
null_type, bool, std::int64_t, std::uint64_t, double,
111 select_on_container_copy_construction(other.
get_allocator())),
112 m_data(other.m_data) {}
117 m_data.template emplace<object_type>(other.
as_object(), m_allocator);
119 m_data.template emplace<array_type>(other.
as_array(), m_allocator);
121 m_data.template emplace<string_type>(other.
as_string(), m_allocator);
123 m_data = other.m_data;
129 : m_allocator(std::move(other.m_allocator)),
130 m_data(std::move(other.m_data)) {
136 : m_allocator(alloc) {
137 if (other.is_object()) {
138 m_data.template emplace<object_type>(std::move(other.as_object()),
140 }
else if (other.is_array()) {
141 m_data.template emplace<array_type>(std::move(other.as_array()),
143 }
else if (other.is_string()) {
144 m_data.template emplace<string_type>(std::move(other.as_string()),
147 m_data = std::move(other.m_data);
157 if (
this == &other)
return *
this;
159 if constexpr (std::is_same_v<
160 typename std::allocator_traits<allocator_type>::
161 propagate_on_container_copy_assignment,
163 m_allocator = other.m_allocator;
176 m_data = other.m_data;
184 if (
this == &other)
return *
this;
186 if constexpr (std::is_same_v<
187 typename std::allocator_traits<allocator_type>::
188 propagate_on_container_move_assignment,
190 m_allocator = std::move(other.m_allocator);
193 if (other.is_object()) {
195 }
else if (other.is_array()) {
197 }
else if (other.is_string()) {
200 m_data = std::move(other.m_data);
211 if constexpr (std::is_same_v<
212 typename std::allocator_traits<
215 swap(m_allocator, other.m_allocator);
221 swap(m_data, other.m_data);
234 return operator=(
static_cast<long long>(i));
240 return operator=(
static_cast<long long>(i));
250 return operator=(
static_cast<long long>(i));
263 return operator=(
static_cast<unsigned long long>(u));
269 return operator=(
static_cast<unsigned long long>(u));
275 return operator=(
static_cast<unsigned long long>(u));
281 return operator=(
static_cast<unsigned long long>(u));
371 return m_data.template emplace<bool>();
378 return m_data.template emplace<std::int64_t>();
385 return m_data.template emplace<std::uint64_t>();
392 return m_data.template emplace<double>();
399 return m_data.template emplace<string_type>(m_allocator);
406 return m_data.template emplace<array_type>(m_allocator);
413 return m_data.template emplace<object_type>(m_allocator);
417 bool &
as_bool() {
return std::get<bool>(m_data); }
421 const bool &
as_bool()
const {
return std::get<bool>(m_data); }
425 std::int64_t &
as_int64() {
return std::get<std::int64_t>(m_data); }
430 return std::get<std::int64_t>(m_data);
435 std::uint64_t &
as_uint64() {
return std::get<std::uint64_t>(m_data); }
440 return std::get<std::uint64_t>(m_data);
444 double &
as_double() {
return std::get<double>(m_data); }
448 const double &
as_double()
const {
return std::get<double>(m_data); }
473 return std::holds_alternative<null_type>(m_data);
477 bool is_bool() const noexcept {
return std::holds_alternative<bool>(m_data); }
481 return std::holds_alternative<int64_t>(m_data);
486 return std::holds_alternative<uint64_t>(m_data);
491 return std::holds_alternative<double>(m_data);
496 return std::holds_alternative<string_type>(m_data);
501 return std::holds_alternative<array_type>(m_data);
506 return std::holds_alternative<object_type>(m_data);
524 return !(lhs == rhs);
529 m_data.template emplace<null_type>();
538 template <
typename allocator_type>