2011-10-20 04:15:24 +00:00
|
|
|
#ifndef SPROUT_NUMERIC_FIXED_ADJACENT_DIFFERENCE_HPP
|
|
|
|
#define SPROUT_NUMERIC_FIXED_ADJACENT_DIFFERENCE_HPP
|
|
|
|
|
|
|
|
#include <type_traits>
|
|
|
|
#include <sprout/config.hpp>
|
2012-03-31 07:24:13 +00:00
|
|
|
#include <sprout/container/traits.hpp>
|
|
|
|
#include <sprout/container/functions.hpp>
|
2011-10-20 04:15:24 +00:00
|
|
|
#include <sprout/iterator/operation.hpp>
|
|
|
|
#include <sprout/algorithm/fixed/result_of.hpp>
|
|
|
|
|
|
|
|
namespace sprout {
|
|
|
|
namespace fixed {
|
|
|
|
namespace detail {
|
|
|
|
template<typename InputIterator, typename Result, typename... Args>
|
2012-04-04 13:23:41 +00:00
|
|
|
inline SPROUT_CONSTEXPR typename std::enable_if<
|
2012-03-31 07:24:13 +00:00
|
|
|
sprout::container_traits<Result>::static_size == sizeof...(Args),
|
2011-10-20 04:15:24 +00:00
|
|
|
typename sprout::fixed::result_of::algorithm<Result>::type
|
2012-02-25 02:51:23 +00:00
|
|
|
>::type adjacent_difference_impl_1(
|
2011-10-20 04:15:24 +00:00
|
|
|
InputIterator first,
|
|
|
|
InputIterator last,
|
|
|
|
Result const& result,
|
2012-03-31 07:24:13 +00:00
|
|
|
typename sprout::container_traits<Result>::size_type size,
|
|
|
|
typename sprout::container_traits<Result>::value_type const& value,
|
2011-10-20 04:15:24 +00:00
|
|
|
Args const&... args
|
|
|
|
)
|
|
|
|
{
|
2012-03-31 07:24:13 +00:00
|
|
|
return sprout::remake<Result>(result, sprout::size(result), args...);
|
2011-10-20 04:15:24 +00:00
|
|
|
}
|
|
|
|
template<typename InputIterator, typename Result, typename... Args>
|
2012-04-04 13:23:41 +00:00
|
|
|
inline SPROUT_CONSTEXPR typename std::enable_if<
|
2012-03-31 07:24:13 +00:00
|
|
|
sprout::container_traits<Result>::static_size != sizeof...(Args),
|
2011-10-20 04:15:24 +00:00
|
|
|
typename sprout::fixed::result_of::algorithm<Result>::type
|
2012-02-25 02:51:23 +00:00
|
|
|
>::type adjacent_difference_impl_1(
|
2011-10-20 04:15:24 +00:00
|
|
|
InputIterator first,
|
|
|
|
InputIterator last,
|
|
|
|
Result const& result,
|
2012-03-31 07:24:13 +00:00
|
|
|
typename sprout::container_traits<Result>::size_type size,
|
|
|
|
typename sprout::container_traits<Result>::value_type const& value,
|
2011-10-20 04:15:24 +00:00
|
|
|
Args const&... args
|
|
|
|
)
|
|
|
|
{
|
2012-02-25 02:51:23 +00:00
|
|
|
return first != last && sizeof...(Args) < size
|
|
|
|
? adjacent_difference_impl_1(sprout::next(first), last, result, size, *first, args..., *first - value)
|
|
|
|
: sprout::detail::container_complate(result, args...)
|
2011-10-20 04:15:24 +00:00
|
|
|
;
|
|
|
|
}
|
2012-02-25 02:51:23 +00:00
|
|
|
template<typename InputIterator, typename Result>
|
2012-04-04 13:23:41 +00:00
|
|
|
inline SPROUT_CONSTEXPR typename std::enable_if<
|
2012-03-31 07:24:13 +00:00
|
|
|
sprout::container_traits<Result>::static_size == 0,
|
2011-10-20 04:15:24 +00:00
|
|
|
typename sprout::fixed::result_of::algorithm<Result>::type
|
2012-02-25 02:51:23 +00:00
|
|
|
>::type adjacent_difference_impl(
|
2011-10-20 04:15:24 +00:00
|
|
|
InputIterator first,
|
|
|
|
InputIterator last,
|
|
|
|
Result const& result,
|
2012-03-31 07:24:13 +00:00
|
|
|
typename sprout::container_traits<Result>::size_type size
|
2011-10-20 04:15:24 +00:00
|
|
|
)
|
|
|
|
{
|
2012-03-31 07:24:13 +00:00
|
|
|
return sprout::remake<Result>(result, sprout::size(result));
|
2011-10-20 04:15:24 +00:00
|
|
|
}
|
2012-02-25 02:51:23 +00:00
|
|
|
template<typename InputIterator, typename Result>
|
2012-04-04 13:23:41 +00:00
|
|
|
inline SPROUT_CONSTEXPR typename std::enable_if<
|
2012-03-31 07:24:13 +00:00
|
|
|
sprout::container_traits<Result>::static_size != 0,
|
2011-10-20 04:15:24 +00:00
|
|
|
typename sprout::fixed::result_of::algorithm<Result>::type
|
|
|
|
>::type adjacent_difference_impl_1(
|
|
|
|
InputIterator first,
|
|
|
|
InputIterator last,
|
|
|
|
Result const& result,
|
2012-03-31 07:24:13 +00:00
|
|
|
typename sprout::container_traits<Result>::size_type size
|
2011-10-20 04:15:24 +00:00
|
|
|
)
|
|
|
|
{
|
2012-02-25 02:51:23 +00:00
|
|
|
return first != last
|
|
|
|
? adjacent_difference_impl_1(sprout::next(first), last, result, size, *first, *first)
|
|
|
|
: sprout::detail::container_complate(result)
|
2011-10-20 04:15:24 +00:00
|
|
|
;
|
|
|
|
}
|
|
|
|
} // namespace detail
|
|
|
|
//
|
|
|
|
// adjacent_difference
|
|
|
|
//
|
|
|
|
template<typename InputIterator, typename Result>
|
2012-04-04 13:23:41 +00:00
|
|
|
inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm<Result>::type adjacent_difference(
|
2011-10-20 04:15:24 +00:00
|
|
|
InputIterator first,
|
|
|
|
InputIterator last,
|
|
|
|
Result const& result
|
|
|
|
)
|
|
|
|
{
|
2012-02-25 02:51:23 +00:00
|
|
|
return sprout::fixed::detail::adjacent_difference_impl(first, last, result, sprout::size(result));
|
2011-10-20 04:15:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace detail {
|
|
|
|
template<typename InputIterator, typename Result, typename BinaryOperation, typename... Args>
|
2012-04-04 13:23:41 +00:00
|
|
|
inline SPROUT_CONSTEXPR typename std::enable_if<
|
2012-03-31 07:24:13 +00:00
|
|
|
sprout::container_traits<Result>::static_size == sizeof...(Args),
|
2011-10-20 04:15:24 +00:00
|
|
|
typename sprout::fixed::result_of::algorithm<Result>::type
|
2012-02-25 02:51:23 +00:00
|
|
|
>::type adjacent_difference_impl_1(
|
2011-10-20 04:15:24 +00:00
|
|
|
InputIterator first,
|
|
|
|
InputIterator last,
|
|
|
|
Result const& result,
|
|
|
|
BinaryOperation binary_op,
|
2012-03-31 07:24:13 +00:00
|
|
|
typename sprout::container_traits<Result>::size_type size,
|
|
|
|
typename sprout::container_traits<Result>::value_type const& value,
|
2011-10-20 04:15:24 +00:00
|
|
|
Args const&... args
|
|
|
|
)
|
|
|
|
{
|
2012-03-31 07:24:13 +00:00
|
|
|
return sprout::remake<Result>(result, sprout::size(result), args...);
|
2011-10-20 04:15:24 +00:00
|
|
|
}
|
|
|
|
template<typename InputIterator, typename Result, typename BinaryOperation, typename... Args>
|
2012-04-04 13:23:41 +00:00
|
|
|
inline SPROUT_CONSTEXPR typename std::enable_if<
|
2012-03-31 07:24:13 +00:00
|
|
|
sprout::container_traits<Result>::static_size != sizeof...(Args),
|
2011-10-20 04:15:24 +00:00
|
|
|
typename sprout::fixed::result_of::algorithm<Result>::type
|
2012-02-25 02:51:23 +00:00
|
|
|
>::type adjacent_difference_impl_1(
|
2011-10-20 04:15:24 +00:00
|
|
|
InputIterator first,
|
|
|
|
InputIterator last,
|
|
|
|
Result const& result,
|
|
|
|
BinaryOperation binary_op,
|
2012-03-31 07:24:13 +00:00
|
|
|
typename sprout::container_traits<Result>::size_type size,
|
|
|
|
typename sprout::container_traits<Result>::value_type const& value,
|
2011-10-20 04:15:24 +00:00
|
|
|
Args const&... args
|
|
|
|
)
|
|
|
|
{
|
2012-02-25 02:51:23 +00:00
|
|
|
return first != last && sizeof...(Args) < size
|
|
|
|
? adjacent_difference_impl_1(sprout::next(first), last, result, binary_op, size, *first, args..., binary_op(*first, value))
|
|
|
|
: sprout::detail::container_complate(result, args...)
|
2011-10-20 04:15:24 +00:00
|
|
|
;
|
|
|
|
}
|
2012-02-25 02:51:23 +00:00
|
|
|
template<typename InputIterator, typename Result, typename BinaryOperation>
|
2012-04-04 13:23:41 +00:00
|
|
|
inline SPROUT_CONSTEXPR typename std::enable_if<
|
2012-03-31 07:24:13 +00:00
|
|
|
sprout::container_traits<Result>::static_size == 0,
|
2011-10-20 04:15:24 +00:00
|
|
|
typename sprout::fixed::result_of::algorithm<Result>::type
|
2012-02-25 02:51:23 +00:00
|
|
|
>::type adjacent_difference_impl(
|
2011-10-20 04:15:24 +00:00
|
|
|
InputIterator first,
|
|
|
|
InputIterator last,
|
|
|
|
Result const& result,
|
|
|
|
BinaryOperation binary_op,
|
2012-03-31 07:24:13 +00:00
|
|
|
typename sprout::container_traits<Result>::size_type size
|
2011-10-20 04:15:24 +00:00
|
|
|
)
|
|
|
|
{
|
2012-03-31 07:24:13 +00:00
|
|
|
return sprout::remake<Result>(result, sprout::size(result));
|
2011-10-20 04:15:24 +00:00
|
|
|
}
|
2012-02-25 02:51:23 +00:00
|
|
|
template<typename InputIterator, typename Result, typename BinaryOperation>
|
2012-04-04 13:23:41 +00:00
|
|
|
inline SPROUT_CONSTEXPR typename std::enable_if<
|
2012-03-31 07:24:13 +00:00
|
|
|
sprout::container_traits<Result>::static_size != 0,
|
2011-10-20 04:15:24 +00:00
|
|
|
typename sprout::fixed::result_of::algorithm<Result>::type
|
|
|
|
>::type adjacent_difference_impl_1(
|
|
|
|
InputIterator first,
|
|
|
|
InputIterator last,
|
|
|
|
Result const& result,
|
|
|
|
BinaryOperation binary_op,
|
2012-03-31 07:24:13 +00:00
|
|
|
typename sprout::container_traits<Result>::size_type size
|
2011-10-20 04:15:24 +00:00
|
|
|
)
|
|
|
|
{
|
2012-02-25 02:51:23 +00:00
|
|
|
return first != last
|
|
|
|
? adjacent_difference_impl_1(sprout::next(first), last, result, binary_op, size, *first, *first)
|
|
|
|
: sprout::detail::container_complate(result)
|
2011-10-20 04:15:24 +00:00
|
|
|
;
|
|
|
|
}
|
|
|
|
} // namespace detail
|
|
|
|
//
|
|
|
|
// adjacent_difference
|
|
|
|
//
|
|
|
|
template<typename InputIterator, typename Result, typename BinaryOperation>
|
2012-04-04 13:23:41 +00:00
|
|
|
inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm<Result>::type adjacent_difference(
|
2011-10-20 04:15:24 +00:00
|
|
|
InputIterator first,
|
|
|
|
InputIterator last,
|
|
|
|
Result const& result,
|
|
|
|
BinaryOperation binary_op
|
|
|
|
)
|
|
|
|
{
|
2012-02-25 02:51:23 +00:00
|
|
|
return sprout::fixed::detail::adjacent_difference_impl(first, last, result, binary_op, sprout::size(result));
|
2011-10-20 04:15:24 +00:00
|
|
|
}
|
|
|
|
} // namespace fixed
|
|
|
|
|
|
|
|
using sprout::fixed::adjacent_difference;
|
|
|
|
} // namespace sprout
|
|
|
|
|
|
|
|
#endif // #ifndef SPROUT_NUMERIC_FIXED_ADJACENT_DIFFERENCE_HPP
|