summaryrefslogtreecommitdiffhomepage
path: root/compat
diff options
context:
space:
mode:
Diffstat (limited to 'compat')
-rw-r--r--compat/macros.hpp16
-rw-r--r--compat/math.hpp38
2 files changed, 23 insertions, 31 deletions
diff --git a/compat/macros.hpp b/compat/macros.hpp
index 42d5d649..5d82c4ee 100644
--- a/compat/macros.hpp
+++ b/compat/macros.hpp
@@ -12,12 +12,6 @@
# define cc_forceinline __attribute__((always_inline))
#endif
-#if defined _MSC_VER
-# define cc_warn_unused_result _Check_return_
-#else
-# define cc_warn_unused_result __attribute__((warn_unused_result))
-#endif
-
#if !defined likely
# if defined __GNUC__
# define likely(x) __builtin_expect(!!(x),1)
@@ -65,7 +59,7 @@ template<typename t>
using remove_cvref_t = typename cxx20_compat::remove_cvref<t>::type;
template<typename t>
-using to_const_lvalue_reference_t = remove_cvref_t<t> const&;
+using to_const_cvref_t = std::add_lvalue_reference_t<std::add_const_t<remove_cvref_t<t>>>;
// causes ICE in Visual Studio 2017 Preview. the ICE was reported and they handle them seriously in due time.
// the ICE is caused by decltype(auto) and const& return value
@@ -77,15 +71,15 @@ using to_const_lvalue_reference_t = remove_cvref_t<t> const&;
#define eval_once__3(expr, ident) \
([&]() -> decltype(auto) { \
static auto INIT##ident = (expr); \
- return static_cast<to_const_lvalue_reference_t<decltype(INIT##ident)>>(INIT##ident); \
+ return static_cast<to_const_cvref_t<decltype(INIT##ident)>>(INIT##ident); \
}())
#include <type_traits>
template<typename t>
-using cv_qualified = std::conditional_t<std::is_fundamental_v<std::decay_t<t>>,
- std::decay_t<t>,
- std::add_lvalue_reference_t<std::add_const_t<remove_cvref_t<t>>>>;
+using cv_qualified = std::conditional_t<std::is_fundamental_v<remove_cvref_t<t>>,
+ remove_cvref_t<t>,
+ to_const_cvref_t<t>>;
template<bool>
[[deprecated]] constexpr cc_forceinline void static_warn() {}
diff --git a/compat/math.hpp b/compat/math.hpp
index 04a6e08d..656e10a8 100644
--- a/compat/math.hpp
+++ b/compat/math.hpp
@@ -13,10 +13,10 @@ inline auto clamp_float(n val, n min_, n max_)
return std::fmin(std::fmax(val, min_), max_);
}
-template<typename t, typename n>
+template<typename t>
struct clamp final
{
- static inline auto clamp_(const n& val, const n& min_, const n& max_)
+ static inline auto clamp_(t val, t min_, t max_)
{
if (unlikely(val > max_))
return max_;
@@ -26,8 +26,8 @@ struct clamp final
}
};
-template<typename t>
-struct clamp<float, t>
+template<>
+struct clamp<float>
{
static inline auto clamp_(float val, float min_, float max_)
{
@@ -35,8 +35,8 @@ struct clamp<float, t>
}
};
-template<typename t>
-struct clamp<double, t>
+template<>
+struct clamp<double>
{
static inline auto clamp_(double val, double min_, double max_)
{
@@ -46,29 +46,27 @@ struct clamp<double, t>
} // ns util_detail
-template<typename t, typename u, typename w>
-inline auto clamp(const t& val, const u& min, const w& max)
+template<typename t, typename u, typename v>
+inline auto clamp(const t& val, const u& min, const v& max)
{
- using tp = decltype(val + min + max);
- return ::util_detail::clamp<std::decay_t<tp>, tp>::clamp_(val, min, max);
+ using w = cv_qualified<decltype(val + min + max)>;
+ return ::util_detail::clamp<w>::clamp_(val, min, max);
}
-template<typename t, typename integral_type = int>
-inline auto iround(t val) -> std::enable_if_t<!std::is_integral_v<std::decay_t<t>>, integral_type>
+template<typename t>
+inline auto iround(t val) -> std::enable_if_t<std::is_floating_point_v<remove_cvref_t<t>>, int>
{
- return static_cast<integral_type>(std::round(val));
+ return (int)std::round(val);
}
template<typename t>
-inline auto uround(const t& val) -> std::enable_if_t<!std::is_integral_v<std::decay_t<t>>, t>
+inline auto uround(t val) -> std::enable_if_t<std::is_floating_point_v<remove_cvref_t<t>>, unsigned>
{
- return (unsigned) std::fmax(0, std::round(val));
+ return (unsigned)std::fmax(0, std::round(val));
}
-#include "macros.hpp"
-
-template <typename T>
-static cc_forceinline constexpr auto signum(T x)
+template <typename t>
+static cc_forceinline constexpr int signum(const t& x)
{
- return x < T(0) ? -1 : 1;
+ return x < t{0} ? -1 : 1;
}