mirror of
https://github.com/bolero-MURAKAMI/Sprout
synced 2024-11-12 21:09:01 +00:00
reimplementation types::fold
This commit is contained in:
parent
84b6d5d994
commit
78e954aa58
1 changed files with 32 additions and 11 deletions
|
@ -8,7 +8,6 @@
|
||||||
#ifndef SPROUT_TYPE_ALGORITHM_FOLD_HPP
|
#ifndef SPROUT_TYPE_ALGORITHM_FOLD_HPP
|
||||||
#define SPROUT_TYPE_ALGORITHM_FOLD_HPP
|
#define SPROUT_TYPE_ALGORITHM_FOLD_HPP
|
||||||
|
|
||||||
#include <sprout/config.hpp>
|
|
||||||
#include <sprout/workaround/std/cstddef.hpp>
|
#include <sprout/workaround/std/cstddef.hpp>
|
||||||
#include <sprout/type/apply.hpp>
|
#include <sprout/type/apply.hpp>
|
||||||
#include <sprout/type/tuple.hpp>
|
#include <sprout/type/tuple.hpp>
|
||||||
|
@ -18,30 +17,52 @@ namespace sprout {
|
||||||
namespace types {
|
namespace types {
|
||||||
namespace detail {
|
namespace detail {
|
||||||
template<
|
template<
|
||||||
typename Tuple, typename T, typename BinaryOp, std::size_t I,
|
typename Tuple, typename T, typename BinaryOp, std::size_t First, std::size_t Last,
|
||||||
bool Valid = (I != sprout::types::tuple_size<Tuple>::value)
|
std::size_t Pivot,
|
||||||
|
bool C0 = (Pivot == 0)
|
||||||
>
|
>
|
||||||
struct fold_impl;
|
struct fold_impl;
|
||||||
template<typename Tuple, typename T, typename BinaryOp, std::size_t I>
|
template<
|
||||||
struct fold_impl<Tuple, T, BinaryOp, I, false>
|
typename Tuple, typename T, typename BinaryOp, std::size_t First, std::size_t Last,
|
||||||
: public sprout::identity<T>
|
std::size_t Pivot
|
||||||
|
>
|
||||||
|
struct fold_impl<Tuple, T, BinaryOp, First, Last, Pivot, true>
|
||||||
|
: public sprout::types::apply<BinaryOp, T, typename sprout::types::tuple_element<First, Tuple>::type>
|
||||||
{};
|
{};
|
||||||
template<typename Tuple, typename T, typename BinaryOp, std::size_t I>
|
template<
|
||||||
struct fold_impl<Tuple, T, BinaryOp, I, true>
|
typename Tuple, typename T, typename BinaryOp, std::size_t First, std::size_t Last,
|
||||||
|
std::size_t Pivot
|
||||||
|
>
|
||||||
|
struct fold_impl<Tuple, T, BinaryOp, First, Last, Pivot, false>
|
||||||
: public sprout::types::detail::fold_impl<
|
: public sprout::types::detail::fold_impl<
|
||||||
Tuple,
|
Tuple,
|
||||||
typename sprout::types::apply<BinaryOp, T, typename sprout::types::tuple_element<I, Tuple>::type>::type,
|
typename sprout::types::detail::fold_impl<
|
||||||
|
Tuple,
|
||||||
|
T,
|
||||||
BinaryOp,
|
BinaryOp,
|
||||||
I + 1
|
First, First + Pivot,
|
||||||
|
Pivot / 2
|
||||||
|
>::type,
|
||||||
|
BinaryOp,
|
||||||
|
First + Pivot, Last,
|
||||||
|
(Last - First - Pivot) / 2
|
||||||
>
|
>
|
||||||
{};
|
{};
|
||||||
|
template<typename Tuple, typename T, typename BinaryOp, std::size_t Size = sprout::types::tuple_size<Tuple>::value>
|
||||||
|
struct fold
|
||||||
|
: public sprout::types::detail::fold_impl<Tuple, T, BinaryOp, 0, Size, Size / 2>
|
||||||
|
{};
|
||||||
|
template<typename Tuple, typename T, typename BinaryOp>
|
||||||
|
struct fold<Tuple, T, BinaryOp, 0>
|
||||||
|
: public sprout::identity<T>
|
||||||
|
{};
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
//
|
//
|
||||||
// fold
|
// fold
|
||||||
//
|
//
|
||||||
template<typename Tuple, typename T, typename BinaryOp>
|
template<typename Tuple, typename T, typename BinaryOp>
|
||||||
struct fold
|
struct fold
|
||||||
: public sprout::types::detail::fold_impl<Tuple, T, BinaryOp, 0>
|
: public sprout::types::detail::fold<Tuple, T, BinaryOp>
|
||||||
{};
|
{};
|
||||||
|
|
||||||
#if SPROUT_USE_TEMPLATE_ALIASES
|
#if SPROUT_USE_TEMPLATE_ALIASES
|
||||||
|
|
Loading…
Reference in a new issue