| 369 | |
| 370 | template <typename L, typename R> |
| 371 | constexpr bool cmp_less(L lhs, R rhs) noexcept { |
| 372 | static_assert(std::is_integral_v<L> && std::is_integral_v<R>, "magic_enum::detail::cmp_less requires integral type."); |
| 373 | |
| 374 | if constexpr (std::is_signed_v<L> == std::is_signed_v<R>) { |
| 375 | // If same signedness (both signed or both unsigned). |
| 376 | return lhs < rhs; |
| 377 | } else if constexpr (std::is_same_v<L, bool>) { // bool special case |
| 378 | return static_cast<R>(lhs) < rhs; |
| 379 | } else if constexpr (std::is_same_v<R, bool>) { // bool special case |
| 380 | return lhs < static_cast<L>(rhs); |
| 381 | } else if constexpr (std::is_signed_v<R>) { |
| 382 | // If 'right' is negative, then result is 'false', otherwise cast & compare. |
| 383 | return rhs > 0 && lhs < static_cast<std::make_unsigned_t<R>>(rhs); |
| 384 | } else { |
| 385 | // If 'left' is negative, then result is 'true', otherwise cast & compare. |
| 386 | return lhs < 0 || static_cast<std::make_unsigned_t<L>>(lhs) < rhs; |
| 387 | } |
| 388 | } |
| 389 | |
| 390 | template <typename I> |
| 391 | constexpr I log2(I value) noexcept { |
no outgoing calls
no test coverage detected