From bf0fe591710677b42a3ce910371951fd8b4fd79e Mon Sep 17 00:00:00 2001 From: wjr <1966336874@qq.com> Date: Thu, 8 Aug 2024 14:37:53 +0800 Subject: [PATCH] update json and uninitialized --- include/wjr/container/generic/vector.hpp | 2 +- include/wjr/json/detail.hpp | 21 +- include/wjr/json/document.hpp | 48 -- include/wjr/json/json.hpp | 725 +++++++++++++++++++++++ include/wjr/json/number.hpp | 6 +- include/wjr/memory/uninitialized.hpp | 9 +- 6 files changed, 741 insertions(+), 70 deletions(-) delete mode 100644 include/wjr/json/document.hpp create mode 100644 include/wjr/json/json.hpp diff --git a/include/wjr/container/generic/vector.hpp b/include/wjr/container/generic/vector.hpp index c20b2961..b2ab5da6 100644 --- a/include/wjr/container/generic/vector.hpp +++ b/include/wjr/container/generic/vector.hpp @@ -501,10 +501,10 @@ class basic_vector { typename std::allocator_traits::template rebind_alloc; using _Alty_traits = std::allocator_traits<_Alty>; - using storage_fn_type = container_fn<_Alty>; using __get_size_t = decltype(std::declval().size()); using IteratorTraits = basic_vector_traits; + using storage_fn_type = container_fn<_Alty>; friend class container_fn<_Alty>; template diff --git a/include/wjr/json/detail.hpp b/include/wjr/json/detail.hpp index 58bc8dc4..01b98211 100644 --- a/include/wjr/json/detail.hpp +++ b/include/wjr/json/detail.hpp @@ -48,39 +48,31 @@ template using result = expected; enum class value_t : uint8_t { + null, + boolean, number_unsigned, number_signed, number_float, - null, - boolean, string, object, array, }; using number_unsigned_t = integral_constant; -inline constexpr number_unsigned_t number_unsigned_v = {}; using number_signed_t = integral_constant; -inline constexpr number_signed_t number_signed_v = {}; using number_float_t = integral_constant; -inline constexpr number_float_t number_float_v = {}; using null_t = integral_constant; -inline constexpr null_t null_v = {}; using boolean_t = integral_constant; -inline constexpr boolean_t boolean_v = {}; using string_t = integral_constant; -inline constexpr string_t string_v = {}; using object_t = integral_constant; -inline constexpr object_t object_v = {}; using array_t = integral_constant; -inline constexpr array_t array_v = {}; struct basic_value { basic_value() = default; @@ -92,10 +84,10 @@ struct basic_value { basic_value(null_t) noexcept : m_type(value_t::null) {} basic_value(boolean_t, bool f) noexcept : m_boolean(f), m_type(value_t::boolean) {} - basic_value(number_signed_t, int64_t value) noexcept - : m_number_signed(value), m_type(value_t::number_signed) {} basic_value(number_unsigned_t, uint64_t value) noexcept : m_number_unsigned(value), m_type(value_t::number_signed) {} + basic_value(number_signed_t, int64_t value) noexcept + : m_number_signed(value), m_type(value_t::number_signed) {} basic_value(number_float_t, double value) noexcept : m_number_float(value), m_type(value_t::number_float) {} basic_value(string_t, void *ptr) noexcept : m_ptr(ptr), m_type(value_t::string) {} @@ -103,15 +95,14 @@ struct basic_value { basic_value(array_t, void *ptr) noexcept : m_ptr(ptr), m_type(value_t::array) {} union { + bool m_boolean; uint64_t m_number_unsigned; int64_t m_number_signed; double m_number_float; - std::nullptr_t m_null; - bool m_boolean; void *m_ptr; }; - value_t m_type; + value_t m_type = value_t::null; }; } // namespace wjr::json diff --git a/include/wjr/json/document.hpp b/include/wjr/json/document.hpp deleted file mode 100644 index 2b124946..00000000 --- a/include/wjr/json/document.hpp +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef WJR_JSON_DOCUMENT_HPP__ -#define WJR_JSON_DOCUMENT_HPP__ - -#include - -#include - -namespace wjr::json { - -template -class basic_json; - -template -struct get_relocate_mode> { - static constexpr relocate_t value = relocate_t::trivial; -}; - -template