MCPcopy Create free account
hub / github.com/BehaviorTree/BehaviorTree.CPP / cmp_less

Function cmp_less

include/behaviortree_cpp/contrib/magic_enum.hpp:371–388  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

369
370template <typename L, typename R>
371constexpr 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
390template <typename I>
391constexpr I log2(I value) noexcept {

Callers 2

reflected_minFunction · 0.85
reflected_maxFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected