mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2024-12-25 21:35:41 +00:00
78 lines
2.6 KiB
C++
78 lines
2.6 KiB
C++
#ifndef SPROUT_MATH_LESS_HPP
|
|
#define SPROUT_MATH_LESS_HPP
|
|
|
|
#include <type_traits>
|
|
#include <sprout/config.hpp>
|
|
#include <sprout/math/not_equal_to.hpp>
|
|
#include <sprout/type_traits/arithmetic_promote.hpp>
|
|
#include <sprout/type_traits/enabler_if.hpp>
|
|
|
|
namespace sprout {
|
|
namespace math {
|
|
namespace detail {
|
|
template<
|
|
typename FloatType1, typename FloatType2,
|
|
typename sprout::enabler_if<
|
|
std::is_floating_point<typename sprout::arithmetic_promote<FloatType1, FloatType2>::type>::value
|
|
>::type = sprout::enabler
|
|
>
|
|
inline SPROUT_CONSTEXPR bool
|
|
less(FloatType1 x, FloatType2 y) {
|
|
return sprout::math::not_equal_to(x, y) && x < y;
|
|
}
|
|
|
|
template<
|
|
typename IntType1, typename IntType2,
|
|
typename sprout::enabler_if<
|
|
std::is_integral<typename sprout::arithmetic_promote<IntType1, IntType2>::type>::value
|
|
&& (std::is_unsigned<IntType1>::value == std::is_unsigned<IntType2>::value)
|
|
>::type = sprout::enabler
|
|
>
|
|
inline SPROUT_CONSTEXPR bool
|
|
less(IntType1 x, IntType2 y) {
|
|
return x < y;
|
|
}
|
|
template<
|
|
typename IntType1, typename IntType2,
|
|
typename sprout::enabler_if<
|
|
std::is_integral<typename sprout::arithmetic_promote<IntType1, IntType2>::type>::value
|
|
&& std::is_signed<IntType1>::value && std::is_unsigned<IntType2>::value
|
|
>::type = sprout::enabler
|
|
>
|
|
inline SPROUT_CONSTEXPR bool
|
|
less(IntType1 x, IntType2 y) {
|
|
typedef typename std::make_unsigned<typename sprout::arithmetic_promote<IntType1, IntType2>::type>::type type;
|
|
return x < 0 ? true
|
|
: static_cast<type>(x) < static_cast<type>(y)
|
|
;
|
|
}
|
|
template<
|
|
typename IntType1, typename IntType2,
|
|
typename sprout::enabler_if<
|
|
std::is_integral<typename sprout::arithmetic_promote<IntType1, IntType2>::type>::value
|
|
&& std::is_unsigned<IntType1>::value && std::is_signed<IntType2>::value
|
|
>::type = sprout::enabler
|
|
>
|
|
inline SPROUT_CONSTEXPR bool
|
|
less(IntType1 x, IntType2 y) {
|
|
typedef typename std::make_unsigned<typename sprout::arithmetic_promote<IntType1, IntType2>::type>::type type;
|
|
return y < 0 ? false
|
|
: static_cast<type>(x) < static_cast<type>(y)
|
|
;
|
|
}
|
|
} // namespace detail
|
|
//
|
|
// less
|
|
//
|
|
template<
|
|
typename T, typename U,
|
|
typename sprout::enabler_if<std::is_arithmetic<T>::value && std::is_arithmetic<U>::value>::type = sprout::enabler
|
|
>
|
|
inline SPROUT_CONSTEXPR bool
|
|
less(T x, U y) {
|
|
return sprout::math::detail::less(x, y);
|
|
}
|
|
} // namespace math
|
|
} // namespace sprout
|
|
|
|
#endif // #ifndef SPROUT_MATH_LESS_HPP
|