Skip to content

Commit

Permalink
update tp
Browse files Browse the repository at this point in the history
  • Loading branch information
wjr-z committed Oct 9, 2024
1 parent b032ebb commit 7e41f86
Show file tree
Hide file tree
Showing 21 changed files with 526 additions and 528 deletions.
4 changes: 2 additions & 2 deletions include/wjr/algorithm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<unsigned int, RestLength>());
constant_length_strncasecmp(
a + 4, b + 4, integral_constant<unsigned int, RestLength>());
} else {
static_assert(Length == 7);
return constant_length_strncasecmp(a, b, 4_u) &
Expand Down
2 changes: 1 addition & 1 deletion include/wjr/arch/preview/memory/aligned_alloc_macos.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
3 changes: 1 addition & 2 deletions include/wjr/biginteger/biginteger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3487,8 +3487,7 @@ template <typename S>
from_chars_result<const char *>
from_chars_characters_unchecked(const char *first, const char *last,
basic_biginteger<S> &dst, unsigned int base) noexcept {
return biginteger_detail::__from_chars_impl<false>(first, last, &dst,
base);
return biginteger_detail::__from_chars_impl<false>(first, last, &dst, base);
}

template <typename S>
Expand Down
2 changes: 1 addition & 1 deletion include/wjr/capture_leaf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <tuple>

#include <wjr/crtp/class_base.hpp>
#include <wjr/tp/list.hpp>
#include <wjr/tp/algorithm.hpp>
#include <wjr/type_traits.hpp>

namespace wjr {
Expand Down
2 changes: 1 addition & 1 deletion include/wjr/compressed_pair.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class compressed_pair;
namespace std {

template <typename T, typename U>
struct tuple_size<wjr::compressed_pair<T, U>> : std::integral_constant<size_t, 2> {};
struct tuple_size<wjr::compressed_pair<T, U>> : integral_constant<size_t, 2> {};

template <size_t I, typename T, typename U>
struct tuple_element<I, wjr::compressed_pair<T, U>> {
Expand Down
2 changes: 1 addition & 1 deletion include/wjr/concurrency/lkf_forward_list.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <array>
#include <string_view>
Expand All @@ -25,4 +25,4 @@ class string_map {

} // namespace wjr

#endif // WJR_CONTAINER_CONSTEXPR_MAP_HPP__
#endif // WJR_CONTAINER_CONSTANT_MAP_HPP__
7 changes: 7 additions & 0 deletions include/wjr/container/constant_radix_tree.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#ifndef WJR_CONSTANT_RADIX_TREE_HPP__
#define WJR_CONSTANT_RADIX_TREE_HPP__

namespace wjr {
}

#endif // WJR_CONSTANT_RADIX_TREE_HPP__
3 changes: 2 additions & 1 deletion include/wjr/format/charconv-impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion include/wjr/format/charconv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2211,7 +2211,8 @@ template <typename Value, unsigned int IBase = 10, typename Converter = char_con
WJR_REQUIRES(charconv_detail::__is_valid_converter_v<Value, Converter>)>
WJR_INTRINSIC_INLINE from_chars_result<const char *>
from_chars(const char *first, const char *last, Value &val,
integral_constant<unsigned int, IBase> ic = {}, Converter conv = {}) noexcept {
integral_constant<unsigned int, IBase> ic = {},
Converter conv = {}) noexcept {
return __from_chars_impl(first, last, val, ic, conv);
}

Expand Down
10 changes: 6 additions & 4 deletions include/wjr/format/fastfloat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,16 @@ __from_chars_impl<default_writer<double>, chars_format>(const char *first,
* `fast_float::chars_format::general` which allows both `fixed` and `scientific`.
*/
template <chars_format Fmt = chars_format::general>
from_chars_result<> from_chars(const char *first, const char *last, float &value,
integral_constant<chars_format, Fmt> fmt = {}) noexcept {
from_chars_result<>
from_chars(const char *first, const char *last, float &value,
integral_constant<chars_format, Fmt> fmt = {}) noexcept {
return __from_chars_impl(first, last, default_writer<float>(value), fmt);
}

template <chars_format Fmt = chars_format::general>
from_chars_result<> from_chars(const char *first, const char *last, double &value,
integral_constant<chars_format, Fmt> fmt = {}) noexcept {
from_chars_result<>
from_chars(const char *first, const char *last, double &value,
integral_constant<chars_format, Fmt> fmt = {}) noexcept {
return __from_chars_impl(first, last, default_writer<double>(value), fmt);
}

Expand Down
2 changes: 2 additions & 0 deletions include/wjr/iterator/contiguous_iterator_adpater.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ struct pointer_traits<wjr::contiguous_const_iterator_adapter<Container, Traits>>
"can't convert invalid vector iterator to pointer");
}
#endif

return wjr::to_address(ptr.m_ptr);
}
};
Expand All @@ -361,6 +362,7 @@ struct pointer_traits<wjr::contiguous_iterator_adapter<Container, Traits>> {
"can't convert invalid vector iterator to pointer");
}
#endif

return wjr::to_address(ptr.m_ptr);
}
};
Expand Down
5 changes: 2 additions & 3 deletions include/wjr/json/document.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -505,9 +505,8 @@ void format(Formatter fmt, const basic_document<Traits> &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.
Expand Down
34 changes: 2 additions & 32 deletions include/wjr/math/integral_constant.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,6 @@

namespace wjr {

template <typename T, T val>
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<T, val>) 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<T, val>() const noexcept {
return {};
}

template <typename U, U u>
constexpr auto operator+(integral_constant<U, u>) const noexcept {
constexpr auto result = value + u;
return integral_constant<decltype(result), result>{};
}

template <typename U, U u>
constexpr auto operator-(integral_constant<U, u>) const noexcept {
constexpr auto result = value - u;
return integral_constant<decltype(result), result>{};
}
};

namespace digits_literal_detail {

template <uint64_t Base>
Expand Down Expand Up @@ -123,7 +92,8 @@ WJR_CONST constexpr T parse() noexcept {
#define WJR_REGISTER_INTEGRAL_LITERALS(NAME, TYPE) \
template <char... Chars> \
WJR_CONST WJR_INTRINSIC_CONSTEXPR auto operator"" _##NAME() noexcept \
-> integral_constant<TYPE, digits_literal_detail::parse<TYPE, Chars...>()> { \
-> integral_constant<TYPE, \
digits_literal_detail::parse<TYPE, Chars...>()> { \
return {}; \
}

Expand Down
2 changes: 1 addition & 1 deletion include/wjr/math/uint128_t.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ WJR_INTRINSIC_CONSTEXPR20 uint128_t mul64x64to128(uint64_t a, uint64_t b) noexce
namespace std {

template <>
struct tuple_size<wjr::uint128_t> : std::integral_constant<size_t, 2> {};
struct tuple_size<wjr::uint128_t> : integral_constant<size_t, 2> {};

template <size_t I>
struct tuple_element<I, wjr::uint128_t> {
Expand Down
10 changes: 10 additions & 0 deletions include/wjr/memory/detail.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ WJR_REGISTER_HAS_TYPE(pointer_traits_to_address,

WJR_REGISTER_HAS_TYPE(pointer_access, std::declval<const Ptr &>().operator->(), Ptr);

#if defined(WJR_CXX_20)

template <typename Ptr>
constexpr auto to_address(const Ptr &p) noexcept {
return std::to_address(p);
}

#else

template <typename T>
constexpr T *to_address(T *p) noexcept {
static_assert(!std::is_function_v<T>, "T cannot be a function.");
Expand All @@ -33,6 +42,7 @@ constexpr auto to_address(const Ptr &p) noexcept {
return wjr::to_address(p.operator->());
}
}
#endif

/**
* @return to_address(p.base()).
Expand Down
Loading

0 comments on commit 7e41f86

Please sign in to comment.