/*============================================================================= Copyright (c) 2011-2016 Bolero MURAKAMI https://github.com/bolero-MURAKAMI/Sprout Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) =============================================================================*/ #ifndef SPROUT_ALGORITHM_ABS_DIFF_HPP #define SPROUT_ALGORITHM_ABS_DIFF_HPP #include namespace sprout { // // abs_diff // template inline SPROUT_CONSTEXPR T abs_diff(T const& a, T const& b) { return (a < b) ? b - a : a - b; } template inline SPROUT_CONSTEXPR T abs_diff(T const& a, T const& b, Compare comp) { return comp(a, b) ? b - a : a - b; } template inline SPROUT_CONSTEXPR T abs_diff(T const& a, T const& b, Compare comp, Difference diff) { return comp(a, b) ? diff(b, a) : diff(a, b); } } // namespace sprout #endif // #ifndef SPROUT_ALGORITHM_ABS_DIFF_HPP