diff --git a/dxlibex/algorithm.hpp b/dxlibex/algorithm.hpp index 1f9f991..19d76b0 100644 --- a/dxlibex/algorithm.hpp +++ b/dxlibex/algorithm.hpp @@ -8,6 +8,7 @@ #ifndef DXLE_INC_ALGORITHM_HPP_ #define DXLE_INC_ALGORITHM_HPP_ #include "dxlibex/algorithm/cast_if.hpp" -#include "dxlibex/algorithm/safe_dist.hpp" +#include "dxlibex/algorithm/abs_diff.hpp" +#include "dxlibex/algorithm/safe_dist.hpp"//deprecated #endif //DXLE_INC_ALGORITHM_HPP_ diff --git a/dxlibex/algorithm/abs_diff.hpp b/dxlibex/algorithm/abs_diff.hpp new file mode 100644 index 0000000..2316834 --- /dev/null +++ b/dxlibex/algorithm/abs_diff.hpp @@ -0,0 +1,65 @@ +/*============================================================================= + Copyright (C) 2015-2017 DxLibEx project + https://github.com/Nagarei/DxLibEx/ + + Distributed under the Boost Software License, Version 1.0. + (See http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef DXLE_INC_ALGORITHM_ABS_DIFF_HPP_ +#define DXLE_INC_ALGORITHM_ABS_DIFF_HPP_ +#include "dxlibex/config/defines.h" +#include "dxlibex/type_traits/enable_if.hpp" +#include "dxlibex/type_traits/ignore.hpp" +#include "dxlibex/type_traits/result_of.hpp" +namespace dxle { + template () - std::declval()), decltype(std::declval() - std::declval())>::value + && std::is_same() < std::declval())>::value, + nullptr_t + > = nullptr> + static inline DXLE_CONSTEXPR auto abs_diff(const T1& a, const T2& b) + DXLE_NOEXCEPT_IF( + DXLE_NOEXCEPT_EXPR(std::declval() - std::declval()) + && DXLE_NOEXCEPT_EXPR(std::declval() - std::declval()) + && DXLE_NOEXCEPT_EXPR(std::declval() < std::declval()) + ) + -> decltype(std::declval() - std::declval()) + { + return (a < b) ? b - a : a - b; + } + template () - std::declval()), decltype(std::declval() - std::declval())>::value + && ignore_type()(std::declval(), std::declval()))>::value + && std::is_same>::value, + nullptr_t + > = nullptr> + static inline DXLE_CONSTEXPR auto abs_diff(const T1& a, const T2& b, const Compare& comp) + DXLE_NOEXCEPT_IF( + DXLE_NOEXCEPT_EXPR(std::declval() - std::declval()) + && DXLE_NOEXCEPT_EXPR(std::declval() - std::declval()) + && DXLE_NOEXCEPT_EXPR(std::declval()(std::declval(), std::declval())) + ) + -> decltype(std::declval() - std::declval()) + { + return comp(a, b) ? b - a : a - b; + } + template () - std::declval()), decltype(std::declval() - std::declval())>::value + && ignore_type()(std::declval(), std::declval()))>::value + && ignore_type()(std::declval(), std::declval()))>::value + && std::is_same, result_of_t>::value + && ignore_type()(std::declval(), std::declval()))>::value + && std::is_same>::value, + nullptr_t + > = nullptr> + static inline DXLE_CONSTEXPR result_of abs_diff(const T1& a, const T2& b, const Compare& comp, const Difference& diff) + DXLE_NOEXCEPT_IF( + DXLE_NOEXCEPT_EXPR(std::declval()(std::declval(), std::declval())) + && DXLE_NOEXCEPT_EXPR(std::declval()(std::declval(), std::declval())) + && DXLE_NOEXCEPT_EXPR(std::declval()(std::declval(), std::declval())) + ) + { + return comp(a, b) ? diff(b, a) : diff(a, b); + } +} +#endif //DXLE_INC_ALGORITHM_ABS_DIFF_HPP_ diff --git a/dxlibex/algorithm/safe_dist.hpp b/dxlibex/algorithm/safe_dist.hpp index df3e8c4..1a9ccd7 100644 --- a/dxlibex/algorithm/safe_dist.hpp +++ b/dxlibex/algorithm/safe_dist.hpp @@ -1,4 +1,4 @@ -/*============================================================================= +/*============================================================================= Copyright (C) 2015-2017 DxLibEx project https://github.com/Nagarei/DxLibEx/ @@ -11,7 +11,7 @@ #include "dxlibex/type_traits/enable_if.hpp" namespace dxle { template - DXLE_CONSTEXPR auto safe_dist(const T1& n1, const T2& n2) DXLE_NOEXCEPT_IF_EXPR((n1 - n2)) -> decltype(n1 - n2) + DXLE_DEPRECATED_MESSAGE("use abs_diff() instead.") static inline DXLE_CONSTEXPR auto safe_dist(const T1& n1, const T2& n2) DXLE_NOEXCEPT_IF_EXPR((n1 - n2)) -> decltype(n1 - n2) { return (n1 < n2) ? n2 - n1 : n1 - n2; } diff --git a/dxlibex/basic_types/point2d.hpp b/dxlibex/basic_types/point2d.hpp index eab16fc..327ed89 100644 --- a/dxlibex/basic_types/point2d.hpp +++ b/dxlibex/basic_types/point2d.hpp @@ -658,9 +658,9 @@ namespace dxle { */ template distance_result_type_t distance(const point_c& p1, const point_c& p2) - DXLE_NOEXCEPT_IF_EXPR(hypot(safe_dist(std::declval(), std::declval()), safe_dist(std::declval(), std::declval()))) + DXLE_NOEXCEPT_IF_EXPR(hypot(abs_diff(std::declval(), std::declval()), abs_diff(std::declval(), std::declval()))) { - return hypot(safe_dist(p1.x, p2.x), safe_dist(p1.y, p2.y)); + return hypot(abs_diff(p1.x, p2.x), abs_diff(p1.y, p2.y)); } typedef point_c pointi; typedef point_c pointu8i; diff --git a/dxlibex/basic_types/point3d.hpp b/dxlibex/basic_types/point3d.hpp index 09e4d01..990b6dc 100644 --- a/dxlibex/basic_types/point3d.hpp +++ b/dxlibex/basic_types/point3d.hpp @@ -128,7 +128,7 @@ namespace dxle { //!1. operator bool //!2. operator != (nullptr) //!3. default constector + operator != - DXLE_CONSTEXPR explicit operator bool() + DXLE_CONSTEXPR explicit operator bool() const DXLE_NOEXCEPT_IF_EXPR((dxle::detail::operator_bool_helper(std::declval(), std::declval(), std::declval()))) { return dxle::detail::operator_bool_helper(this->x, this->y, this->z); @@ -640,11 +640,11 @@ namespace dxle { \~japanese @return 計算結果。 \~english @return Computed result. */ - template + template distance_result_type_t distance(const point3d_c& p1, const point3d_c& p2) - DXLE_NOEXCEPT_IF_EXPR(hypot(safe_dist(std::declval(), std::declval()), safe_dist(std::declval(), std::declval()))) + DXLE_NOEXCEPT_IF_EXPR(hypot(abs_diff(std::declval(), std::declval()), abs_diff(std::declval(), std::declval()))) { - return hypot(safe_dist(p1.x, p2.x), hypot(safe_dist(p1.y, p2.y), safe_dist(p1.z, p2.z))); + return hypot(abs_diff(p1.x, p2.x), hypot(abs_diff(p1.y, p2.y), abs_diff(p1.z, p2.z))); } typedef point3d_c point3di; typedef point3d_c point3du8i; diff --git a/dxlibex/type_traits.hpp b/dxlibex/type_traits.hpp index 80688a2..005b152 100644 --- a/dxlibex/type_traits.hpp +++ b/dxlibex/type_traits.hpp @@ -17,5 +17,7 @@ #include "dxlibex/type_traits/is_nothrow.hpp" #include "dxlibex/type_traits/is_representable.hpp" #include "dxlibex/type_traits/is_well_format.hpp" +#include "dxlibex/type_traits/result_of.hpp" + #endif//#ifndef DXLE_INC_TYPE_TRAITS_HPP_ diff --git a/dxlibex/type_traits/result_of.hpp b/dxlibex/type_traits/result_of.hpp new file mode 100644 index 0000000..0485563 --- /dev/null +++ b/dxlibex/type_traits/result_of.hpp @@ -0,0 +1,21 @@ +/*============================================================================= + Copyright (C) 2015-2017 DxLibEx project + https://github.com/Nagarei/DxLibEx/ + + Distributed under the Boost Software License, Version 1.0. + (See http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef DXLE_INC_TYPE_TRAITS_RESULT_OF_HPP_ +#define DXLE_INC_TYPE_TRAITS_RESULT_OF_HPP_ +#include +#include "enable_if.hpp" +namespace dxle { +//!inline +namespace type_traits { + using std::result_of; + template + using result_of_t = typename result_of::type; +}//namespace +using namespace type_traits; +} +#endif //DXLE_INC_TYPE_TRAITS_RESULT_OF_HPP_