mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2025-07-06 14:24:09 +00:00
add tuples::apply
This commit is contained in:
parent
a1f6d6ffc3
commit
5ccbc4e903
16 changed files with 280 additions and 52 deletions
34
sprout/algorithm/abs_diff.hpp
Normal file
34
sprout/algorithm/abs_diff.hpp
Normal file
|
@ -0,0 +1,34 @@
|
|||
/*=============================================================================
|
||||
Copyright (c) 2011-2014 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 <sprout/config.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// abs_diff
|
||||
//
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR T
|
||||
abs_diff(T const& a, T const& b) {
|
||||
return (a < b) ? b - a : a - b;
|
||||
}
|
||||
template<typename T, typename Compare>
|
||||
inline SPROUT_CONSTEXPR T
|
||||
abs_diff(T const& a, T const& b, Compare comp) {
|
||||
return comp(a, b) ? b - a : a - b;
|
||||
}
|
||||
template<typename T, typename Compare, typename Difference>
|
||||
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
|
Loading…
Add table
Add a link
Reference in a new issue