-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfold.hpp
32 lines (28 loc) · 981 Bytes
/
fold.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Copyright David Abrahams 2009. 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 FOLD_DWA200957_HPP
# define FOLD_DWA200957_HPP
# include "./apply.hpp"
# include "./list.hpp"
# include "./empty.hpp"
# include "./front.hpp"
# include "./pop_front.hpp"
extern struct fold_
{
template <class Fn, class X, class Seq>
auto
operator()(Fn& fn, type_<X>& x, type_<Seq>& s)
-> decltype(type<X>());
template <class Fn, class X, class Seq>
auto
operator()(type_<Fn>& fn, type_<X>& x, type_<Seq>& s)
-> decltype(
fold(
type<Fn>(), // fn
apply(type<Fn>(), type<X>(), front(type<Seq>())), // fn(x,front(s))
pop_front(type<Seq>()) // pop_front(s)
)
);
} & fold;
#endif // FOLD_DWA200957_HPP