diff --git a/include/mgutility/reflection/detail/enum_for_each.hpp b/include/mgutility/reflection/detail/enum_for_each.hpp index 49b54ee..bb96547 100644 --- a/include/mgutility/reflection/detail/enum_for_each.hpp +++ b/include/mgutility/reflection/detail/enum_for_each.hpp @@ -74,7 +74,7 @@ template class enum_for_each { * @brief An iterator for enum values. */ struct enum_iter { - using const_iter_type = decltype(enum_range::min); + using const_iter_type = int; using iter_type = detail::remove_const_t; using iterator_category = std::forward_iterator_tag; using value_type = const detail::enum_pair; @@ -172,12 +172,12 @@ template class enum_for_each { * @return The size of the enum range. */ auto size() -> std::size_t { - return enum_range::max - enum_range::min; + return static_cast(enum_range::max) - static_cast(enum_range::min) + 1; } private: - enum_iter m_begin{enum_range::min}; /**< The beginning iterator. */ - enum_iter m_end{enum_range::max}; /**< The end iterator. */ + enum_iter m_begin{static_cast(enum_range::min)}; /**< The beginning iterator. */ + enum_iter m_end{static_cast(enum_range::max) + 1}; /**< The end iterator. */ }; } // namespace mgutility diff --git a/include/mgutility/reflection/detail/enum_name_impl.hpp b/include/mgutility/reflection/detail/enum_name_impl.hpp index 14040d6..38497fa 100644 --- a/include/mgutility/reflection/detail/enum_name_impl.hpp +++ b/include/mgutility/reflection/detail/enum_name_impl.hpp @@ -179,7 +179,7 @@ get_enum_array(detail::enum_sequence /*unused*/) noexcept template ::min, int Max = mgutility::enum_range::max> MGUTILITY_CNSTXPR inline auto get_enum_array() noexcept - -> std::array { + -> std::array { return get_enum_array(detail::make_enum_sequence()); } diff --git a/include/mgutility/reflection/detail/meta.hpp b/include/mgutility/reflection/detail/meta.hpp index 6f28844..1903b55 100644 --- a/include/mgutility/reflection/detail/meta.hpp +++ b/include/mgutility/reflection/detail/meta.hpp @@ -145,7 +145,7 @@ struct enum_sequence_helper { * @tparam Max The maximum value in the sequence. */ template -using make_enum_sequence = typename enum_sequence_helper::type; +using make_enum_sequence = typename enum_sequence_helper::type; } // namespace detail /** diff --git a/include/mgutility/reflection/enum_name.hpp b/include/mgutility/reflection/enum_name.hpp index 430ef7f..2b07e3f 100644 --- a/include/mgutility/reflection/enum_name.hpp +++ b/include/mgutility/reflection/enum_name.hpp @@ -27,7 +27,6 @@ SOFTWARE. #include "detail/enum_name_impl.hpp" - namespace mgutility { /** @@ -56,7 +55,7 @@ constexpr auto enum_to_underlying(Enum enumValue) noexcept template MGUTILITY_CNSTXPR auto enum_name(Enum enumValue) noexcept -> detail::string_or_view_t { - static_assert(Min < Max - 1, "Max must be greater than (Min + 1)!"); + static_assert(Min < Max, "Max must be greater than Min!"); static_assert(std::is_enum::value, "Value is not an Enum type!"); return detail::enum_name_impl(enumValue); } @@ -70,11 +69,11 @@ MGUTILITY_CNSTXPR auto enum_name(Enum enumValue) noexcept * @param e The enum value. * @return A string view or string representing the name of the enum value. */ -template ::min, - int Max = enum_range::max> +template (enum_range::min), + int Max = static_cast(enum_range::max)> MGUTILITY_CNSTXPR auto enum_name(Enum enumValue) noexcept -> detail::string_or_view_t { - static_assert(Min < Max - 1, "Max must be greater than (Min + 1)!"); + static_assert(Min < Max, "Max must be greater than Min!"); static_assert(std::is_enum::value, "Value is not an Enum type!"); return detail::enum_name_impl(enumValue); } @@ -100,12 +99,12 @@ auto enum_for_each::enum_iter::operator*() const -> value_type { * @param str The string view representing the enum name. * @return An optional enum value. */ -template ::min, - int Max = enum_range::max, +template (enum_range::min), + int Max = static_cast(enum_range::max), detail::enable_if_t::value, bool> = true> MGUTILITY_CNSTXPR auto to_enum(mgutility::string_view str) noexcept -> mgutility::optional { - static_assert(Min < Max - 1, "Max must be greater than (Min + 1)!"); + static_assert(Min < Max, "Max must be greater than Min!"); static_assert(std::is_enum::value, "Type is not an Enum type!"); return detail::to_enum_impl(str); } @@ -119,12 +118,12 @@ MGUTILITY_CNSTXPR auto to_enum(mgutility::string_view str) noexcept * @param str The string view representing the enum name. * @return An optional enum bitmask value. */ -template ::min, - int Max = enum_range::max, +template (enum_range::min), + int Max = static_cast(enum_range::max), detail::enable_if_t::value, bool> = true> MGUTILITY_CNSTXPR auto to_enum(mgutility::string_view str) noexcept -> mgutility::optional { - static_assert(Min < Max - 1, "Max must be greater than (Min + 1)!"); + static_assert(Min < Max, "Max must be greater than Min!"); static_assert(std::is_enum::value, "Type is not an Enum type!"); return detail::to_enum_bitmask_impl(str); } @@ -138,11 +137,11 @@ MGUTILITY_CNSTXPR auto to_enum(mgutility::string_view str) noexcept * @param value The integer value to cast. * @return An optional enum value. */ -template ::min, - int Max = enum_range::max> +template (enum_range::min), + int Max = static_cast(enum_range::max)> MGUTILITY_CNSTXPR auto enum_cast(int value) noexcept -> mgutility::optional { - static_assert(Min < Max - 1, "Max must be greater than (Min + 1)!"); + static_assert(Min < Max, "Max must be greater than Min!"); static_assert(std::is_enum::value, "Type is not an Enum type!"); if (enum_name(static_cast(value)).empty()) { return mgutility::nullopt; @@ -153,14 +152,14 @@ MGUTILITY_CNSTXPR auto enum_cast(int value) noexcept namespace operators { template ::value, bool> = true> -inline constexpr auto operator&(const Enum &lhs, const Enum &rhs) -> Enum { + constexpr auto operator&(const Enum &lhs, const Enum &rhs) -> Enum { return static_cast(mgutility::enum_to_underlying(lhs) & mgutility::enum_to_underlying(rhs)); } template ::value, bool> = true> -inline constexpr auto operator|(const Enum &lhs, const Enum &rhs) -> Enum { + constexpr auto operator|(const Enum &lhs, const Enum &rhs) -> Enum { return static_cast(mgutility::enum_to_underlying(lhs) | mgutility::enum_to_underlying(rhs)); } @@ -178,10 +177,10 @@ inline constexpr auto operator|(const Enum &lhs, const Enum &rhs) -> Enum { */ template ::value, bool> = true> -auto operator<<(std::ostream &os, Enum e) -> std::ostream & { +auto operator<<(std::ostream &outStream, Enum enumVal) -> std::ostream & { static_assert(std::is_enum::value, "Value is not an Enum type!"); - os << mgutility::enum_name(e); - return os; + outStream << mgutility::enum_name(enumVal); + return outStream; } #if defined(__cpp_lib_format)