From 83867b413c449101bbe14615ff857a7785432ede Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Thu, 25 Oct 2018 17:55:27 +0200 Subject: cleanup only - replace warn_unused_result with [[nodiscard]] - remove some redundant w_a_r - replace std::decay with remove_cvref_t - simplify compat/math.hpp --- compat/macros.hpp | 16 +++++----------- compat/math.hpp | 38 ++++++++++++++++++-------------------- 2 files changed, 23 insertions(+), 31 deletions(-) (limited to 'compat') 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 using remove_cvref_t = typename cxx20_compat::remove_cvref::type; template -using to_const_lvalue_reference_t = remove_cvref_t const&; +using to_const_cvref_t = std::add_lvalue_reference_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 const&; #define eval_once__3(expr, ident) \ ([&]() -> decltype(auto) { \ static auto INIT##ident = (expr); \ - return static_cast>(INIT##ident); \ + return static_cast>(INIT##ident); \ }()) #include template -using cv_qualified = std::conditional_t>, - std::decay_t, - std::add_lvalue_reference_t>>>; +using cv_qualified = std::conditional_t>, + remove_cvref_t, + to_const_cvref_t>; template [[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 +template 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 -struct clamp +template<> +struct clamp { static inline auto clamp_(float val, float min_, float max_) { @@ -35,8 +35,8 @@ struct clamp } }; -template -struct clamp +template<> +struct clamp { static inline auto clamp_(double val, double min_, double max_) { @@ -46,29 +46,27 @@ struct clamp } // ns util_detail -template -inline auto clamp(const t& val, const u& min, const w& max) +template +inline auto clamp(const t& val, const u& min, const v& max) { - using tp = decltype(val + min + max); - return ::util_detail::clamp, tp>::clamp_(val, min, max); + using w = cv_qualified; + return ::util_detail::clamp::clamp_(val, min, max); } -template -inline auto iround(t val) -> std::enable_if_t>, integral_type> +template +inline auto iround(t val) -> std::enable_if_t>, int> { - return static_cast(std::round(val)); + return (int)std::round(val); } template -inline auto uround(const t& val) -> std::enable_if_t>, t> +inline auto uround(t val) -> std::enable_if_t>, unsigned> { - return (unsigned) std::fmax(0, std::round(val)); + return (unsigned)std::fmax(0, std::round(val)); } -#include "macros.hpp" - -template -static cc_forceinline constexpr auto signum(T x) +template +static cc_forceinline constexpr int signum(const t& x) { - return x < T(0) ? -1 : 1; + return x < t{0} ? -1 : 1; } -- cgit v1.2.3