| 418 | |
| 419 | template <typename L, typename R> |
| 420 | constexpr bool cmp_less(L lhs, R rhs) noexcept { |
| 421 | static_assert(std::is_integral_v<L> && std::is_integral_v<R>, "magic_enum::detail::cmp_less requires integral type."); |
| 422 | |
| 423 | if constexpr (std::is_signed_v<L> == std::is_signed_v<R>) { |
| 424 | // If same signedness (both signed or both unsigned). |
| 425 | return lhs < rhs; |
| 426 | } else if constexpr (std::is_same_v<L, bool>) { // bool special case |
| 427 | return static_cast<R>(lhs) < rhs; |
| 428 | } else if constexpr (std::is_same_v<R, bool>) { // bool special case |
| 429 | return lhs < static_cast<L>(rhs); |
| 430 | } else if constexpr (std::is_signed_v<R>) { |
| 431 | // If 'right' is negative, then result is 'false', otherwise cast & compare. |
| 432 | return rhs > 0 && lhs < static_cast<std::make_unsigned_t<R>>(rhs); |
| 433 | } else { |
| 434 | // If 'left' is negative, then result is 'true', otherwise cast & compare. |
| 435 | return lhs < 0 || static_cast<std::make_unsigned_t<L>>(lhs) < rhs; |
| 436 | } |
| 437 | } |
| 438 | |
| 439 | template <typename I> |
| 440 | constexpr I log2(I value) noexcept { |
no outgoing calls
no test coverage detected