MCPcopy Create free account
hub / github.com/Neargye/magic_enum / cmp_less

Function cmp_less

include/magic_enum/magic_enum.hpp:420–437  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

418
419template <typename L, typename R>
420constexpr 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
439template <typename I>
440constexpr I log2(I value) noexcept {

Callers 3

test.cppFile · 0.85
reflected_minFunction · 0.85
reflected_maxFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected