From 7e41f86515de6b0cc6609c830b8d6ed24358441a Mon Sep 17 00:00:00 2001 From: wjr <1966336874@qq.com> Date: Wed, 9 Oct 2024 22:34:56 +0800 Subject: [PATCH] update tp --- include/wjr/algorithm.hpp | 4 +- .../preview/memory/aligned_alloc_macos.hpp | 2 +- include/wjr/biginteger/biginteger.hpp | 3 +- include/wjr/capture_leaf.hpp | 2 +- include/wjr/compressed_pair.hpp | 2 +- include/wjr/concurrency/lkf_forward_list.hpp | 2 +- .../{constexpr_map.hpp => constant_map.hpp} | 6 +- include/wjr/container/constant_radix_tree.hpp | 7 + include/wjr/format/charconv-impl.hpp | 3 +- include/wjr/format/charconv.hpp | 3 +- include/wjr/format/fastfloat.hpp | 10 +- .../iterator/contiguous_iterator_adpater.hpp | 2 + include/wjr/json/document.hpp | 5 +- include/wjr/math/integral_constant.hpp | 34 +- include/wjr/math/uint128_t.hpp | 2 +- include/wjr/memory/detail.hpp | 10 + include/wjr/tp/algorithm.hpp | 439 +++++++++++++++ include/wjr/tp/compiler.hpp | 8 - include/wjr/tp/{list.hpp => detail.hpp} | 503 ++---------------- include/wjr/tuple.hpp | 5 +- include/wjr/type_traits.hpp | 2 + 21 files changed, 526 insertions(+), 528 deletions(-) rename include/wjr/container/{constexpr_map.hpp => constant_map.hpp} (75%) create mode 100644 include/wjr/container/constant_radix_tree.hpp create mode 100644 include/wjr/tp/algorithm.hpp delete mode 100644 include/wjr/tp/compiler.hpp rename include/wjr/tp/{list.hpp => detail.hpp} (53%) diff --git a/include/wjr/algorithm.hpp b/include/wjr/algorithm.hpp index 4d981de2..a8cd546b 100644 --- a/include/wjr/algorithm.hpp +++ b/include/wjr/algorithm.hpp @@ -190,8 +190,8 @@ constant_length_strncasecmp(const char *a, const char *b, } else if constexpr (Length >= 5 && Length <= 6) { constexpr auto RestLength = Length - 4; return constant_length_strncasecmp(a, b, 4_u) & - constant_length_strncasecmp(a + 4, b + 4, - integral_constant()); + constant_length_strncasecmp( + a + 4, b + 4, integral_constant()); } else { static_assert(Length == 7); return constant_length_strncasecmp(a, b, 4_u) & diff --git a/include/wjr/arch/preview/memory/aligned_alloc_macos.hpp b/include/wjr/arch/preview/memory/aligned_alloc_macos.hpp index 1e2bf5e4..63abe43e 100644 --- a/include/wjr/arch/preview/memory/aligned_alloc_macos.hpp +++ b/include/wjr/arch/preview/memory/aligned_alloc_macos.hpp @@ -9,7 +9,7 @@ namespace wjr { WJR_MALLOC inline void *aligned_alloc(size_t size, size_t alignment) noexcept { WJR_ASSERT(has_single_bit(alignment)); - + if (size == 0) { return 0; } diff --git a/include/wjr/biginteger/biginteger.hpp b/include/wjr/biginteger/biginteger.hpp index becb098c..48809e0c 100644 --- a/include/wjr/biginteger/biginteger.hpp +++ b/include/wjr/biginteger/biginteger.hpp @@ -3487,8 +3487,7 @@ template from_chars_result from_chars_characters_unchecked(const char *first, const char *last, basic_biginteger &dst, unsigned int base) noexcept { - return biginteger_detail::__from_chars_impl(first, last, &dst, - base); + return biginteger_detail::__from_chars_impl(first, last, &dst, base); } template diff --git a/include/wjr/capture_leaf.hpp b/include/wjr/capture_leaf.hpp index caac0f8e..8094754d 100644 --- a/include/wjr/capture_leaf.hpp +++ b/include/wjr/capture_leaf.hpp @@ -4,7 +4,7 @@ #include #include -#include +#include #include namespace wjr { diff --git a/include/wjr/compressed_pair.hpp b/include/wjr/compressed_pair.hpp index 65050cd4..588d2e7d 100644 --- a/include/wjr/compressed_pair.hpp +++ b/include/wjr/compressed_pair.hpp @@ -13,7 +13,7 @@ class compressed_pair; namespace std { template -struct tuple_size> : std::integral_constant {}; +struct tuple_size> : integral_constant {}; template struct tuple_element> { diff --git a/include/wjr/concurrency/lkf_forward_list.hpp b/include/wjr/concurrency/lkf_forward_list.hpp index ac7b4d12..3807826d 100644 --- a/include/wjr/concurrency/lkf_forward_list.hpp +++ b/include/wjr/concurrency/lkf_forward_list.hpp @@ -7,7 +7,7 @@ namespace wjr::intrusive { struct lkf_forward_list_node { - lkf_forward_list_node() noexcept : next(nullptr) {} + lkf_forward_list_node() noexcept : next(nullptr) {} lkf_forward_list_node(const lkf_forward_list_node &) = delete; lkf_forward_list_node &operator=(const lkf_forward_list_node &) = delete; ~lkf_forward_list_node() = default; diff --git a/include/wjr/container/constexpr_map.hpp b/include/wjr/container/constant_map.hpp similarity index 75% rename from include/wjr/container/constexpr_map.hpp rename to include/wjr/container/constant_map.hpp index 30e3a973..f0751cf4 100644 --- a/include/wjr/container/constexpr_map.hpp +++ b/include/wjr/container/constant_map.hpp @@ -1,5 +1,5 @@ -#ifndef WJR_CONTAINER_CONSTEXPR_MAP_HPP__ -#define WJR_CONTAINER_CONSTEXPR_MAP_HPP__ +#ifndef WJR_CONTAINER_CONSTANT_MAP_HPP__ +#define WJR_CONTAINER_CONSTANT_MAP_HPP__ #include #include @@ -25,4 +25,4 @@ class string_map { } // namespace wjr -#endif // WJR_CONTAINER_CONSTEXPR_MAP_HPP__ \ No newline at end of file +#endif // WJR_CONTAINER_CONSTANT_MAP_HPP__ \ No newline at end of file diff --git a/include/wjr/container/constant_radix_tree.hpp b/include/wjr/container/constant_radix_tree.hpp new file mode 100644 index 00000000..6e07ee69 --- /dev/null +++ b/include/wjr/container/constant_radix_tree.hpp @@ -0,0 +1,7 @@ +#ifndef WJR_CONSTANT_RADIX_TREE_HPP__ +#define WJR_CONSTANT_RADIX_TREE_HPP__ + +namespace wjr { +} + +#endif // WJR_CONSTANT_RADIX_TREE_HPP__ \ No newline at end of file diff --git a/include/wjr/format/charconv-impl.hpp b/include/wjr/format/charconv-impl.hpp index 5fb969a9..f0a0465a 100644 --- a/include/wjr/format/charconv-impl.hpp +++ b/include/wjr/format/charconv-impl.hpp @@ -127,7 +127,8 @@ WJR_PURE WJR_INTRINSIC_INLINE bool is_made_of_eight_digits_fast(const char *src) WJR_PURE WJR_INTRINSIC_INLINE uint32_t parse_eight_digits_unrolled(const char *src) noexcept; -WJR_PURE WJR_INTRINSIC_INLINE const char *skip_whitespace(const char *first, const char * last) noexcept; +WJR_PURE WJR_INTRINSIC_INLINE const char *skip_whitespace(const char *first, + const char *last) noexcept; } // namespace wjr diff --git a/include/wjr/format/charconv.hpp b/include/wjr/format/charconv.hpp index 86929dd1..f7f969a2 100644 --- a/include/wjr/format/charconv.hpp +++ b/include/wjr/format/charconv.hpp @@ -2211,7 +2211,8 @@ template )> WJR_INTRINSIC_INLINE from_chars_result from_chars(const char *first, const char *last, Value &val, - integral_constant ic = {}, Converter conv = {}) noexcept { + integral_constant ic = {}, + Converter conv = {}) noexcept { return __from_chars_impl(first, last, val, ic, conv); } diff --git a/include/wjr/format/fastfloat.hpp b/include/wjr/format/fastfloat.hpp index 223bdfb2..97ca1469 100644 --- a/include/wjr/format/fastfloat.hpp +++ b/include/wjr/format/fastfloat.hpp @@ -78,14 +78,16 @@ __from_chars_impl, chars_format>(const char *first, * `fast_float::chars_format::general` which allows both `fixed` and `scientific`. */ template -from_chars_result<> from_chars(const char *first, const char *last, float &value, - integral_constant fmt = {}) noexcept { +from_chars_result<> +from_chars(const char *first, const char *last, float &value, + integral_constant fmt = {}) noexcept { return __from_chars_impl(first, last, default_writer(value), fmt); } template -from_chars_result<> from_chars(const char *first, const char *last, double &value, - integral_constant fmt = {}) noexcept { +from_chars_result<> +from_chars(const char *first, const char *last, double &value, + integral_constant fmt = {}) noexcept { return __from_chars_impl(first, last, default_writer(value), fmt); } diff --git a/include/wjr/iterator/contiguous_iterator_adpater.hpp b/include/wjr/iterator/contiguous_iterator_adpater.hpp index 303a8504..a7d5b88d 100644 --- a/include/wjr/iterator/contiguous_iterator_adpater.hpp +++ b/include/wjr/iterator/contiguous_iterator_adpater.hpp @@ -340,6 +340,7 @@ struct pointer_traits> "can't convert invalid vector iterator to pointer"); } #endif + return wjr::to_address(ptr.m_ptr); } }; @@ -361,6 +362,7 @@ struct pointer_traits> { "can't convert invalid vector iterator to pointer"); } #endif + return wjr::to_address(ptr.m_ptr); } }; diff --git a/include/wjr/json/document.hpp b/include/wjr/json/document.hpp index 1ed79fa9..e690b0c4 100644 --- a/include/wjr/json/document.hpp +++ b/include/wjr/json/document.hpp @@ -505,9 +505,8 @@ void format(Formatter fmt, const basic_document &doc) noexcept { /** * @details At present, it's a simple but flexible implementation solution. This is not as * good as a only iteration in terms of performance. \n - * Performance (use std::map and wjr::vector as container on my local x64 2.50 GHz machine) : \n - * twitter.document : 700~720 MB/s \n - * canada.document : 660~680 MB/s + * Performance (use std::map and wjr::vector as container on my local x64 2.50 GHz + * machine) : \n twitter.document : 700~720 MB/s \n canada.document : 660~680 MB/s * @todo 1. For most strings, only need to check first character to compare. * 2. Maybe use hash like std::unordered_map, but for long strings, compare even faster * than hash. diff --git a/include/wjr/math/integral_constant.hpp b/include/wjr/math/integral_constant.hpp index 9fee8a86..26fcf678 100644 --- a/include/wjr/math/integral_constant.hpp +++ b/include/wjr/math/integral_constant.hpp @@ -5,37 +5,6 @@ namespace wjr { -template -struct integral_constant { - static constexpr T value = val; - - using value_type = T; - using type = integral_constant; - - WJR_ENABLE_DEFAULT_SPECIAL_MEMBERS(integral_constant); - - constexpr integral_constant(std::integral_constant) noexcept {} - - constexpr operator value_type() const noexcept { return value; } - WJR_NODISCARD constexpr value_type operator()() const noexcept { return value; } - - WJR_NODISCARD constexpr operator std::integral_constant() const noexcept { - return {}; - } - - template - constexpr auto operator+(integral_constant) const noexcept { - constexpr auto result = value + u; - return integral_constant{}; - } - - template - constexpr auto operator-(integral_constant) const noexcept { - constexpr auto result = value - u; - return integral_constant{}; - } -}; - namespace digits_literal_detail { template @@ -123,7 +92,8 @@ WJR_CONST constexpr T parse() noexcept { #define WJR_REGISTER_INTEGRAL_LITERALS(NAME, TYPE) \ template \ WJR_CONST WJR_INTRINSIC_CONSTEXPR auto operator"" _##NAME() noexcept \ - -> integral_constant()> { \ + -> integral_constant()> { \ return {}; \ } diff --git a/include/wjr/math/uint128_t.hpp b/include/wjr/math/uint128_t.hpp index 14439ae4..3f83b311 100644 --- a/include/wjr/math/uint128_t.hpp +++ b/include/wjr/math/uint128_t.hpp @@ -202,7 +202,7 @@ WJR_INTRINSIC_CONSTEXPR20 uint128_t mul64x64to128(uint64_t a, uint64_t b) noexce namespace std { template <> -struct tuple_size : std::integral_constant {}; +struct tuple_size : integral_constant {}; template struct tuple_element { diff --git a/include/wjr/memory/detail.hpp b/include/wjr/memory/detail.hpp index e7de37d2..054e24ed 100644 --- a/include/wjr/memory/detail.hpp +++ b/include/wjr/memory/detail.hpp @@ -14,6 +14,15 @@ WJR_REGISTER_HAS_TYPE(pointer_traits_to_address, WJR_REGISTER_HAS_TYPE(pointer_access, std::declval().operator->(), Ptr); +#if defined(WJR_CXX_20) + +template +constexpr auto to_address(const Ptr &p) noexcept { + return std::to_address(p); +} + +#else + template constexpr T *to_address(T *p) noexcept { static_assert(!std::is_function_v, "T cannot be a function."); @@ -33,6 +42,7 @@ constexpr auto to_address(const Ptr &p) noexcept { return wjr::to_address(p.operator->()); } } +#endif /** * @return to_address(p.base()). diff --git a/include/wjr/tp/algorithm.hpp b/include/wjr/tp/algorithm.hpp new file mode 100644 index 00000000..1b074628 --- /dev/null +++ b/include/wjr/tp/algorithm.hpp @@ -0,0 +1,439 @@ +#ifndef WJR_TP_ALGORITHM_HPP__ +#define WJR_TP_ALGORITHM_HPP__ + +#include + +namespace wjr { + +template +struct tp_equal_to : std::is_same {}; + +template +struct tp_not_equal_to : std::negation> {}; + +template +struct tp_less : std::bool_constant<(T::value < U::value)> {}; + +template +struct tp_greater : tp_less {}; + +template +struct tp_less_equal : std::negation> {}; + +template +struct tp_greater_equal : std::negation> {}; + +template typename F> +struct tp_transform; + +template