mirror of
https://github.com/Neargye/magic_enum.git
synced 2026-01-09 23:34:23 +00:00
fix char_type cast
This commit is contained in:
parent
67abcf483a
commit
04ecb134ff
2 changed files with 12 additions and 12 deletions
|
|
@ -138,8 +138,8 @@ using char_type = string_view::value_type;
|
|||
static_assert(std::is_same_v<string_view::value_type, string::value_type>, "magic_enum::customize requires same string_view::value_type and string::value_type");
|
||||
static_assert([] {
|
||||
if constexpr (std::is_same_v<char_type, wchar_t>) {
|
||||
constexpr const char c[] = "abcdefghijklmnopqrstuvwxyz_ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||
constexpr const wchar_t wc[] = L"abcdefghijklmnopqrstuvwxyz_ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||
constexpr const char c[] = "abcdefghijklmnopqrstuvwxyz_ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789|";
|
||||
constexpr const wchar_t wc[] = L"abcdefghijklmnopqrstuvwxyz_ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789|";
|
||||
static_assert(std::size(c) == std::size(wc), "magic_enum::customize identifier characters are multichars in wchar_t.");
|
||||
|
||||
for (std::size_t i = 0; i < std::size(c); ++i) {
|
||||
|
|
@ -263,10 +263,10 @@ class static_str {
|
|||
|
||||
private:
|
||||
template <std::uint16_t... I>
|
||||
constexpr static_str(const char* str, std::integer_sequence<std::uint16_t, I...>) noexcept : chars_{static_cast<char_type>(str[I])..., '\0'} {}
|
||||
constexpr static_str(const char* str, std::integer_sequence<std::uint16_t, I...>) noexcept : chars_{static_cast<char_type>(str[I])..., static_cast<char_type>('\0')} {}
|
||||
|
||||
template <std::uint16_t... I>
|
||||
constexpr static_str(string_view str, std::integer_sequence<std::uint16_t, I...>) noexcept : chars_{str[I]..., '\0'} {}
|
||||
constexpr static_str(string_view str, std::integer_sequence<std::uint16_t, I...>) noexcept : chars_{str[I]..., static_cast<char_type>('\0')} {}
|
||||
|
||||
char_type chars_[static_cast<std::size_t>(N) + 1];
|
||||
};
|
||||
|
|
@ -290,7 +290,7 @@ class static_str<0> {
|
|||
template <typename Op = std::equal_to<>>
|
||||
class case_insensitive {
|
||||
static constexpr char_type to_lower(char_type c) noexcept {
|
||||
return (c >= 'A' && c <= 'Z') ? static_cast<char_type>(c + ('a' - 'A')) : c;
|
||||
return (c >= static_cast<char_type>('A') && c <= static_cast<char_type>('Z')) ? static_cast<char_type>(c + (static_cast<char_type>('a') - static_cast<char_type>('A'))) : c;
|
||||
}
|
||||
|
||||
public:
|
||||
|
|
@ -1234,7 +1234,7 @@ template <detail::enum_subtype S, typename E>
|
|||
// Returns name from enum-flags value.
|
||||
// If enum-flags value does not have name or value out of range, returns empty string.
|
||||
template <typename E>
|
||||
[[nodiscard]] auto enum_flags_name(E value, char_type sep = '|') -> detail::enable_if_t<E, string> {
|
||||
[[nodiscard]] auto enum_flags_name(E value, char_type sep = static_cast<char_type>('|')) -> detail::enable_if_t<E, string> {
|
||||
using D = std::decay_t<E>;
|
||||
using U = underlying_type_t<D>;
|
||||
constexpr auto S = detail::enum_subtype::flags;
|
||||
|
|
|
|||
|
|
@ -546,7 +546,7 @@ class bitset {
|
|||
}
|
||||
}
|
||||
|
||||
constexpr explicit bitset(detail::raw_access_t, string_view sv, string_view::size_type pos = 0, string_view::size_type n = string_view::npos, char_type zero = '0', char_type one = '1')
|
||||
constexpr explicit bitset(detail::raw_access_t, string_view sv, string_view::size_type pos = 0, string_view::size_type n = string_view::npos, char_type zero = static_cast<char_type>('0'), char_type one = static_cast<char_type>('1'))
|
||||
: a{{}} {
|
||||
std::size_t i{};
|
||||
for (auto c : sv.substr(pos, n)) {
|
||||
|
|
@ -562,8 +562,8 @@ class bitset {
|
|||
}
|
||||
}
|
||||
|
||||
constexpr explicit bitset(detail::raw_access_t, const char_type* str, std::size_t n = ~std::size_t{}, char_type zero = '0', char_type one = '1')
|
||||
: bitset(std::string_view{str, (std::min)(std::char_traits<char_type>::length(str), n)}, 0, n, zero, one) {}
|
||||
constexpr explicit bitset(detail::raw_access_t, const char_type* str, std::size_t n = ~std::size_t{}, char_type zero = static_cast<char_type>('0'), char_type one = static_cast<char_type>('1'))
|
||||
: bitset(string_view{str, (std::min)(std::char_traits<char_type>::length(str), n)}, 0, n, zero, one) {}
|
||||
|
||||
constexpr bitset(std::initializer_list<E> starters) : a{{}} {
|
||||
if constexpr (magic_enum::detail::subtype_v<E> == magic_enum::detail::enum_subtype::flags) {
|
||||
|
|
@ -591,7 +591,7 @@ class bitset {
|
|||
}
|
||||
|
||||
template <typename Cmp = std::equal_to<>>
|
||||
constexpr explicit bitset(string_view sv, Cmp&& cmp = {}, char_type sep = '|') {
|
||||
constexpr explicit bitset(string_view sv, Cmp&& cmp = {}, char_type sep = static_cast<char_type>('|')) {
|
||||
for (std::size_t to{}; (to = magic_enum::detail::find(sv, sep)) != string_view::npos; sv.remove_prefix(to + 1)) {
|
||||
if (auto v = enum_cast<E>(sv.substr(0, to), cmp)) {
|
||||
set(v);
|
||||
|
|
@ -756,7 +756,7 @@ class bitset {
|
|||
return res;
|
||||
}
|
||||
|
||||
[[nodiscard]] string to_string(char_type sep = '|') const {
|
||||
[[nodiscard]] string to_string(char_type sep = static_cast<char_type>('|')) const {
|
||||
string name;
|
||||
|
||||
for (auto& e : enum_values<E>()) {
|
||||
|
|
@ -771,7 +771,7 @@ class bitset {
|
|||
return name;
|
||||
}
|
||||
|
||||
[[nodiscard]] string to_string(detail::raw_access_t, char_type zero = '0', char_type one = '1') const {
|
||||
[[nodiscard]] string to_string(detail::raw_access_t, char_type zero = static_cast<char_type>('0'), char_type one = static_cast<char_type>('1')) const {
|
||||
string name;
|
||||
name.reserve(size());
|
||||
for (std::size_t i{}; i < size(); ++i) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue