Skip to content

Commit

Permalink
Sync phmap and format code
Browse files Browse the repository at this point in the history
  • Loading branch information
fcharlie committed Sep 21, 2024
1 parent 162037d commit 9f68386
Show file tree
Hide file tree
Showing 39 changed files with 831 additions and 315 deletions.
2 changes: 1 addition & 1 deletion include/bela/__charconv/to_chars_base_10.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ template <class I> constexpr wchar_t *__append1(wchar_t *__buffer, I __value) no
}

template <class I> constexpr wchar_t *__append2(wchar_t *__buffer, I __value) noexcept {
std::memcpy(__buffer, &__digits_base_10[(__value)*2], 2 * sizeof(wchar_t));
std::memcpy(__buffer, &__digits_base_10[(__value) * 2], 2 * sizeof(wchar_t));
return __buffer + 2;
}

Expand Down
2 changes: 1 addition & 1 deletion include/bela/__phmap/VERSION
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
https://github.com/greg7mdp/parallel-hashmap.git
63acc3336f941c6f324c88eb9ee4ce623a460cd5
60acfa4690303eeefde355175eaaad57c65a113d
4 changes: 2 additions & 2 deletions include/bela/__phmap/phmap_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
// ---------------------------------------------------------------------------

#define PHMAP_VERSION_MAJOR 1
#define PHMAP_VERSION_MINOR 3
#define PHMAP_VERSION_PATCH 12
#define PHMAP_VERSION_MINOR 4
#define PHMAP_VERSION_PATCH 0

// Included for the __GLIBC__ macro (or similar macros on other systems).
#include <limits.h>
Expand Down
20 changes: 15 additions & 5 deletions include/bela/__strings/str_join_internal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,21 @@ template <typename Formatter> class DereferenceFormatterImpl {
//
// AlphaNumFormatterImpl is the default in the base template, followed by
// specializations for other types.
template <typename ValueType> struct DefaultFormatter { typedef AlphaNumFormatterImpl Type; };
template <> struct DefaultFormatter<const wchar_t *> { typedef AlphaNumFormatterImpl Type; };
template <> struct DefaultFormatter<wchar_t *> { typedef AlphaNumFormatterImpl Type; };
template <> struct DefaultFormatter<std::wstring> { typedef NoFormatter Type; };
template <> struct DefaultFormatter<std::wstring_view> { typedef NoFormatter Type; };
template <typename ValueType> struct DefaultFormatter {
typedef AlphaNumFormatterImpl Type;
};
template <> struct DefaultFormatter<const wchar_t *> {
typedef AlphaNumFormatterImpl Type;
};
template <> struct DefaultFormatter<wchar_t *> {
typedef AlphaNumFormatterImpl Type;
};
template <> struct DefaultFormatter<std::wstring> {
typedef NoFormatter Type;
};
template <> struct DefaultFormatter<std::wstring_view> {
typedef NoFormatter Type;
};
template <typename ValueType> struct DefaultFormatter<ValueType *> {
typedef DereferenceFormatterImpl<typename DefaultFormatter<ValueType>::Type> Type;
};
Expand Down
20 changes: 15 additions & 5 deletions include/bela/__strings/str_join_narrow_internal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,21 @@ template <typename Formatter> class DereferenceFormatterImpl {
//
// AlphaNumFormatterImpl is the default in the base template, followed by
// specializations for other types.
template <typename ValueType> struct DefaultFormatter { typedef AlphaNumFormatterImpl Type; };
template <> struct DefaultFormatter<const char *> { typedef AlphaNumFormatterImpl Type; };
template <> struct DefaultFormatter<char *> { typedef AlphaNumFormatterImpl Type; };
template <> struct DefaultFormatter<std::string> { typedef NoFormatter Type; };
template <> struct DefaultFormatter<std::string_view> { typedef NoFormatter Type; };
template <typename ValueType> struct DefaultFormatter {
typedef AlphaNumFormatterImpl Type;
};
template <> struct DefaultFormatter<const char *> {
typedef AlphaNumFormatterImpl Type;
};
template <> struct DefaultFormatter<char *> {
typedef AlphaNumFormatterImpl Type;
};
template <> struct DefaultFormatter<std::string> {
typedef NoFormatter Type;
};
template <> struct DefaultFormatter<std::string_view> {
typedef NoFormatter Type;
};
template <typename ValueType> struct DefaultFormatter<ValueType *> {
typedef DereferenceFormatterImpl<typename DefaultFormatter<ValueType>::Type> Type;
};
Expand Down
2 changes: 1 addition & 1 deletion include/bela/__strings/str_split_internal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ template <typename T> struct HasEmplace<T, std::void_t<decltype(std::declval<T>(
// details below in Splitter<> where this is used.
std::false_type IsInitializerListDispatch(...); // default: No
template <typename T> std::true_type IsInitializerListDispatch(std::initializer_list<T> *);
template <typename T> struct IsInitializerList : decltype(IsInitializerListDispatch(static_cast<T *>(nullptr))) {};
template <typename T> struct IsInitializerList : decltype(IsInitializerListDispatch(static_cast<T *>(nullptr))){};

// A SplitterIsConvertibleTo<C>::type alias exists iff the specified condition
// is true for type 'C'.
Expand Down
2 changes: 1 addition & 1 deletion include/bela/__strings/str_split_narrow_internal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ template <typename T> struct HasEmplace<T, std::void_t<decltype(std::declval<T>(
// details below in Splitter<> where this is used.
std::false_type IsInitializerListDispatch(...); // default: No
template <typename T> std::true_type IsInitializerListDispatch(std::initializer_list<T> *);
template <typename T> struct IsInitializerList : decltype(IsInitializerListDispatch(static_cast<T *>(nullptr))) {};
template <typename T> struct IsInitializerList : decltype(IsInitializerListDispatch(static_cast<T *>(nullptr))){};

// A SplitterIsConvertibleTo<C>::type alias exists iff the specified condition
// is true for type 'C'.
Expand Down
93 changes: 50 additions & 43 deletions include/bela/__strings/string_cat_internal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,20 @@ template <> class Literal<char8_t> {
};

template <typename CharT>
requires bela::character<CharT>
auto boolean_string_view(bool v) { return v ? Literal<CharT>::StringTrue : Literal<CharT>::StringFalse; }
requires bela::character<CharT>
auto boolean_string_view(bool v) {
return v ? Literal<CharT>::StringTrue : Literal<CharT>::StringFalse;
}

template <typename CharT>
requires bela::character<CharT>
requires bela::character<CharT>
auto make_string_view(const CharT *str) {
using string_view_t = std::basic_string_view<CharT, std::char_traits<CharT>>;
return (str == nullptr) ? string_view_t() : string_view_t(str);
}

template <typename To>
requires bela::u16_character<To>
requires bela::u16_character<To>
auto u16string_view_cast(std::wstring_view sv) {
using string_view_t = std::basic_string_view<To, std::char_traits<To>>;
return string_view_t{reinterpret_cast<const To *>(sv.data()), sv.size()};
Expand Down Expand Up @@ -111,19 +113,19 @@ struct Hex {
char fill;

template <typename Int>
requires(sizeof(Int) == 1 && !std::is_pointer_v<Int>) constexpr explicit Hex(Int v, PadSpec spec = kNoPad)
: Hex(spec, static_cast<uint8_t>(v)) {}
requires(sizeof(Int) == 1 && !std::is_pointer_v<Int>)
constexpr explicit Hex(Int v, PadSpec spec = kNoPad) : Hex(spec, static_cast<uint8_t>(v)) {}
template <typename Int>
requires(sizeof(Int) == 2 && !std::is_pointer_v<Int>) constexpr explicit Hex(Int v, PadSpec spec = kNoPad)
: Hex(spec, static_cast<uint16_t>(v)) {}
requires(sizeof(Int) == 2 && !std::is_pointer_v<Int>)
constexpr explicit Hex(Int v, PadSpec spec = kNoPad) : Hex(spec, static_cast<uint16_t>(v)) {}
template <typename Int>
requires(sizeof(Int) == 4 && !std::is_pointer_v<Int>) constexpr explicit Hex(Int v, PadSpec spec = kNoPad)
: Hex(spec, static_cast<uint32_t>(v)) {}
requires(sizeof(Int) == 4 && !std::is_pointer_v<Int>)
constexpr explicit Hex(Int v, PadSpec spec = kNoPad) : Hex(spec, static_cast<uint32_t>(v)) {}
template <typename Int>
requires(sizeof(Int) == 8 && !std::is_pointer_v<Int>) constexpr explicit Hex(Int v, PadSpec spec = kNoPad)
: Hex(spec, static_cast<uint64_t>(v)) {}
requires(sizeof(Int) == 8 && !std::is_pointer_v<Int>)
constexpr explicit Hex(Int v, PadSpec spec = kNoPad) : Hex(spec, static_cast<uint64_t>(v)) {}
template <typename Pointer>
requires std::is_pointer_v<Pointer>
requires std::is_pointer_v<Pointer>
explicit Hex(Pointer *v, PadSpec spec = kNoPad) : Hex(spec, reinterpret_cast<uintptr_t>(v)) {}

private:
Expand All @@ -148,7 +150,7 @@ struct Dec {
bool neg;

template <typename Int>
requires std::integral<Int>
requires std::integral<Int>
constexpr explicit Dec(Int v, PadSpec spec = kNoPad)
: value(v >= 0 ? static_cast<uint64_t>(v) : uint64_t{0} - static_cast<uint64_t>(v)),
width(spec == kNoPad ? 1
Expand All @@ -171,24 +173,27 @@ template <typename CharT> class basic_alphanum {
public:
using string_view_t = std::basic_string_view<CharT, std::char_traits<CharT>>;
template <typename I>
requires bela::strict_integral<I> basic_alphanum(I x) : piece_(bela::to_chars_view(digits_, x)) {}
requires bela::strict_integral<I>
basic_alphanum(I x) : piece_(bela::to_chars_view(digits_, x)) {}
template <typename F>
requires std::floating_point<F> basic_alphanum(F x)
: piece_(bela::to_chars_view(digits_, x, std::chars_format::general)) {}
requires std::floating_point<F>
basic_alphanum(F x) : piece_(bela::to_chars_view(digits_, x, std::chars_format::general)) {}
template <typename From>
requires bela::compatible_character<From, CharT> basic_alphanum(const From *c_str)
requires bela::compatible_character<From, CharT>
basic_alphanum(const From *c_str)
: piece_(strings_internal::make_string_view(reinterpret_cast<const CharT *>(c_str))) {}
template <typename From>
requires bela::compatible_character<From, CharT>
requires bela::compatible_character<From, CharT>
basic_alphanum(std::basic_string_view<From, std::char_traits<From>> pc)
: piece_{reinterpret_cast<const CharT *>(pc.data()), pc.size()} {}

template <typename From, typename Allocator>
requires bela::compatible_character<From, CharT>
requires bela::compatible_character<From, CharT>
basic_alphanum(const std::basic_string<From, std::char_traits<From>, Allocator> &str)
: piece_{reinterpret_cast<const CharT *>(str.data()), str.size()} {}
template <typename From>
requires bela::compatible_character<From, CharT> basic_alphanum(From ch) : piece_(digits_, 1) {
requires bela::compatible_character<From, CharT>
basic_alphanum(From ch) : piece_(digits_, 1) {
digits_[0] = static_cast<CharT>(ch);
}
basic_alphanum(bool b) : piece_{strings_internal::boolean_string_view<CharT>(b)} {}
Expand All @@ -203,23 +208,24 @@ template <typename CharT> class basic_alphanum {
// Extended type support
// eg: std::filesystem::path
template <typename E>
requires(has_u16_native<E> &&std::same_as<CharT, wchar_t>) basic_alphanum(const E &e) : piece_{e.native()} {}
requires(has_u16_native<E> && std::same_as<CharT, wchar_t>)
basic_alphanum(const E &e) : piece_{e.native()} {}
template <typename E>
requires(has_u16_native<E> &&std::same_as<CharT, char16_t>) basic_alphanum(const E &e)
: piece_{strings_internal::u16string_view_cast<CharT>(e.native())} {}
requires(has_u16_native<E> && std::same_as<CharT, char16_t>)
basic_alphanum(const E &e) : piece_{strings_internal::u16string_view_cast<CharT>(e.native())} {}

// Normal enums are already handled by the integer formatters.
// This overload matches only scoped enums.
template <typename T>
requires(std::is_enum_v<T> &&std::integral<std::underlying_type_t<T>>) basic_alphanum(T e)
: piece_(bela::to_chars_view(digits_, bela::integral_cast(e))) {}
requires(std::is_enum_v<T> && std::integral<std::underlying_type_t<T>>)
basic_alphanum(T e) : piece_(bela::to_chars_view(digits_, bela::integral_cast(e))) {}

// vector<bool>::reference and const_reference require special help to
// convert to `AlphaNum` because it requires two user defined conversions.
template <typename T>
requires(std::is_class_v<T> && (std::is_same_v<T, std::vector<bool>::reference> ||
std::is_same_v<T, std::vector<bool>::const_reference>)) basic_alphanum(T e)
: basic_alphanum(static_cast<bool>(e)) {} // NOLINT(runtime/explicit)
requires(std::is_class_v<T> &&
(std::is_same_v<T, std::vector<bool>::reference> || std::is_same_v<T, std::vector<bool>::const_reference>))
basic_alphanum(T e) : basic_alphanum(static_cast<bool>(e)) {} // NOLINT(runtime/explicit)

// template <typename T>
// requires has_u16_native<T> basic_alphanum(const T &t) : piece_(t.native()) {}
Expand All @@ -238,7 +244,7 @@ using AlphaNumNarrow = basic_alphanum<char>;

namespace strings_internal {
template <typename CharT, typename Allocator = std::allocator<CharT>>
requires bela::character<CharT>
requires bela::character<CharT>
auto string_cat_pieces(std::initializer_list<std::basic_string_view<CharT, std::char_traits<CharT>>> pieces) {
std::basic_string<CharT, std::char_traits<CharT>, Allocator> result;
size_t total_size = 0;
Expand All @@ -259,7 +265,7 @@ auto string_cat_pieces(std::initializer_list<std::basic_string_view<CharT, std::
}

template <typename CharT, typename Allocator = std::allocator<CharT>>
requires bela::character<CharT>
requires bela::character<CharT>
void string_append_pieces(std::basic_string<CharT, std::char_traits<CharT>, Allocator> *dest,
std::initializer_list<std::basic_string_view<CharT, std::char_traits<CharT>>> pieces) {
size_t old_size = dest->size();
Expand All @@ -280,7 +286,8 @@ void string_append_pieces(std::basic_string<CharT, std::char_traits<CharT>, Allo
}

template <typename CharT>
requires bela::character<CharT> size_t buffer_unchecked_concat(CharT *out, const basic_alphanum<CharT> &a) {
requires bela::character<CharT>
size_t buffer_unchecked_concat(CharT *out, const basic_alphanum<CharT> &a) {
if (a.size() != 0) {
memcpy(out, a.data(), a.size() * sizeof(CharT));
}
Expand All @@ -289,20 +296,20 @@ requires bela::character<CharT> size_t buffer_unchecked_concat(CharT *out, const
} // namespace strings_internal

template <typename CharT = wchar_t, typename Allocator = std::allocator<CharT>>
requires bela::character<CharT>
requires bela::character<CharT>
[[nodiscard]] inline std::basic_string<CharT, std::char_traits<CharT>, Allocator> string_cat() {
return std::basic_string<CharT, std::char_traits<CharT>, Allocator>();
}

template <typename CharT = wchar_t, typename Allocator = std::allocator<CharT>>
requires bela::character<CharT>
requires bela::character<CharT>
[[nodiscard]] inline std::basic_string<CharT, std::char_traits<CharT>, Allocator>
string_cat(const basic_alphanum<CharT> &a) {
return std::basic_string<CharT, std::char_traits<CharT>, Allocator>(a.Piece());
}

template <typename CharT = wchar_t, typename Allocator = std::allocator<CharT>>
requires bela::character<CharT>
requires bela::character<CharT>
[[nodiscard]] inline std::basic_string<CharT, std::char_traits<CharT>, Allocator>
string_cat(const basic_alphanum<CharT> &a, const basic_alphanum<CharT> &b) {
std::basic_string<CharT, std::char_traits<CharT>, Allocator> s;
Expand All @@ -314,7 +321,7 @@ string_cat(const basic_alphanum<CharT> &a, const basic_alphanum<CharT> &b) {
}

template <typename CharT = wchar_t, typename Allocator = std::allocator<CharT>>
requires bela::character<CharT>
requires bela::character<CharT>
[[nodiscard]] inline std::basic_string<CharT, std::char_traits<CharT>, Allocator>
string_cat(const basic_alphanum<CharT> &a, const basic_alphanum<CharT> &b, const basic_alphanum<CharT> &c) {
std::basic_string<CharT, std::char_traits<CharT>, Allocator> s;
Expand All @@ -327,7 +334,7 @@ string_cat(const basic_alphanum<CharT> &a, const basic_alphanum<CharT> &b, const
}

template <typename CharT = wchar_t, typename Allocator = std::allocator<CharT>>
requires bela::character<CharT>
requires bela::character<CharT>
[[nodiscard]] inline std::basic_string<CharT, std::char_traits<CharT>, Allocator>
string_cat(const basic_alphanum<CharT> &a, const basic_alphanum<CharT> &b, const basic_alphanum<CharT> &c,
const basic_alphanum<CharT> &d) {
Expand All @@ -342,7 +349,7 @@ string_cat(const basic_alphanum<CharT> &a, const basic_alphanum<CharT> &b, const
}

template <typename CharT, typename Allocator, typename... AV>
requires bela::character<CharT>
requires bela::character<CharT>
[[nodiscard]] inline auto string_cat_with_allocator(const basic_alphanum<CharT> &a, const basic_alphanum<CharT> &b,
const basic_alphanum<CharT> &c, const basic_alphanum<CharT> &d,
const basic_alphanum<CharT> &e, const AV &...args) {
Expand All @@ -352,7 +359,7 @@ requires bela::character<CharT>
}

template <typename CharT, typename... AV>
requires bela::character<CharT>
requires bela::character<CharT>
[[nodiscard]] inline auto string_cat(const basic_alphanum<CharT> &a, const basic_alphanum<CharT> &b,
const basic_alphanum<CharT> &c, const basic_alphanum<CharT> &d,
const basic_alphanum<CharT> &e, const AV &...args) {
Expand All @@ -361,13 +368,13 @@ requires bela::character<CharT>
}

template <typename CharT = wchar_t, typename Allocator = std::allocator<CharT>>
requires bela::character<CharT>
requires bela::character<CharT>
void string_append(std::basic_string<CharT, std::char_traits<CharT>, Allocator> *dest, const basic_alphanum<CharT> &a) {
dest->append(a.Piece());
}

template <typename CharT = wchar_t, typename Allocator = std::allocator<CharT>>
requires bela::character<CharT>
requires bela::character<CharT>
void string_append(std::basic_string<CharT, std::char_traits<CharT>, Allocator> *dest, const basic_alphanum<CharT> &a,
const basic_alphanum<CharT> &b) {
auto oldsize = dest->size();
Expand All @@ -378,7 +385,7 @@ void string_append(std::basic_string<CharT, std::char_traits<CharT>, Allocator>
}

template <typename CharT = wchar_t, typename Allocator = std::allocator<CharT>>
requires bela::character<CharT>
requires bela::character<CharT>
void string_append(std::basic_string<CharT, std::char_traits<CharT>, Allocator> *dest, const basic_alphanum<CharT> &a,
const basic_alphanum<CharT> &b, const basic_alphanum<CharT> &c) {
auto oldsize = dest->size();
Expand All @@ -390,7 +397,7 @@ void string_append(std::basic_string<CharT, std::char_traits<CharT>, Allocator>
}

template <typename CharT = wchar_t, typename Allocator = std::allocator<CharT>>
requires bela::character<CharT>
requires bela::character<CharT>
void string_append(std::basic_string<CharT, std::char_traits<CharT>, Allocator> *dest, const basic_alphanum<CharT> &a,
const basic_alphanum<CharT> &b, const basic_alphanum<CharT> &c, const basic_alphanum<CharT> &d) {
auto oldsize = dest->size();
Expand Down
Loading

0 comments on commit 9f68386

Please sign in to comment.