1
0
Fork 0
mirror of https://github.com/Neargye/magic_enum.git synced 2026-01-09 23:34:23 +00:00

Fix optional masos (#160)

This commit is contained in:
Daniil Goncharov 2022-03-09 16:32:45 +02:00 committed by GitHub
parent b0c0e02bdc
commit 74123638d1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -897,7 +897,7 @@ template <auto V>
constexpr auto index = enum_index<std::decay_t<decltype(V)>>(V); constexpr auto index = enum_index<std::decay_t<decltype(V)>>(V);
static_assert(index.has_value(), "magic_enum::enum_index enum value does not have a index."); static_assert(index.has_value(), "magic_enum::enum_index enum value does not have a index.");
return index.value(); return *index;
} }
// Checks whether enum contains enumerator with such enum value. // Checks whether enum contains enumerator with such enum value.
@ -929,7 +929,7 @@ template <typename E>
constexpr optional<std::uintmax_t> fuse_one_enum(optional<std::uintmax_t> hash, E value) noexcept { constexpr optional<std::uintmax_t> fuse_one_enum(optional<std::uintmax_t> hash, E value) noexcept {
if (hash.has_value()) { if (hash.has_value()) {
if (const auto index = enum_index(value); index.has_value()) { if (const auto index = enum_index(value); index.has_value()) {
return (hash.value() << log2(enum_count<E>() + 1)) | index.value(); return (*hash << log2(enum_count<E>() + 1)) | *index;
} }
} }
return {}; return {};
@ -950,7 +950,7 @@ constexpr auto typesafe_fuse_enum(Es... values) noexcept {
enum class enum_fuse_t : std::uintmax_t; enum class enum_fuse_t : std::uintmax_t;
const auto fuse = fuse_enum(values...); const auto fuse = fuse_enum(values...);
if (fuse.has_value()) { if (fuse.has_value()) {
return optional<enum_fuse_t>{static_cast<enum_fuse_t>(fuse.value())}; return optional<enum_fuse_t>{static_cast<enum_fuse_t>(*fuse)};
} }
return optional<enum_fuse_t>{}; return optional<enum_fuse_t>{};
} }
@ -991,7 +991,7 @@ std::basic_ostream<Char, Traits>& operator<<(std::basic_ostream<Char, Traits>& o
template <typename Char, typename Traits, typename E, detail::enable_if_enum_t<E, int> = 0> template <typename Char, typename Traits, typename E, detail::enable_if_enum_t<E, int> = 0>
std::basic_ostream<Char, Traits>& operator<<(std::basic_ostream<Char, Traits>& os, optional<E> value) { std::basic_ostream<Char, Traits>& operator<<(std::basic_ostream<Char, Traits>& os, optional<E> value) {
return value.has_value() ? (os << value.value()) : os; return value.has_value() ? (os << *value) : os;
} }
} // namespace magic_enum::ostream_operators } // namespace magic_enum::ostream_operators