-
Notifications
You must be signed in to change notification settings - Fork 0
/
bind.hpp
63 lines (50 loc) · 1.69 KB
/
bind.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// bind.hpp
//
// Copyright (c) 2009
// Steven Watanabe
//
// 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 MPL0X_BIND_HPP_INCLUDED
#define MPL0X_BIND_HPP_INCLUDED
#include "./type.hpp"
extern struct bind_
{
template<class Fn, class...Args>
auto operator()(type_<Fn>& fn, type_<Args>&...args)
-> decltype(
type<bind_(type_<Fn>&, type_<Args>&...)>()
);
} & bind;
template<class Fn, class... BindArgs, class... Args>
auto apply_impl(type_<bind_(type_<Fn>&, type_<BindArgs>&...)>&, type_<Args>&...)
-> decltype(
bind_impl(type<bind_(type_<Fn>&, type_<BindArgs>&...)>(), type<Args>()...)
);
template<class Fn, class... BindArgs, class... Args>
auto bind_impl(type_<bind_(type_<Fn>&, type_<BindArgs>&...)>&, type_<Args>&...)
-> decltype(
apply(bind_impl(type<Fn>(), type<Args>()...), bind_impl(type<BindArgs>(), type<Args>()...)...)
);
template<class t, class...args>
auto bind_impl(type_<t>&, type_<args>&...)
-> decltype(
type<t>()
);
template<int N>
struct arg_;
template<int N>
auto arg() -> decltype(type<arg_<N> >());
extern type_<arg_<1> > & _1;
extern type_<arg_<2> > & _2;
extern type_<arg_<3> > & _3;
template<class Front, class...Rest>
auto bind_impl(type_<arg_<1> >&, type_<Front>&, type_<Rest>&...)
-> decltype(type<Front>());
template<int N, class Front, class...Rest>
auto bind_impl(type_<arg_<N> >&, type_<Front>&, type_<Rest>&...)
-> decltype(bind_impl(arg<N-1>(), type<Rest>()...));
template<class Fn, class...Args>
int make(type_<bind_(type_<Fn>&, type_<Args>&...)>&);
#endif