]>
Commit | Line | Data |
---|---|---|
b32b8144 FG |
1 | #ifndef BOOST_MP11_BIND_HPP_INCLUDED |
2 | #define BOOST_MP11_BIND_HPP_INCLUDED | |
3 | ||
4 | // Copyright 2017 Peter Dimov. | |
5 | // | |
6 | // Distributed under the Boost Software License, Version 1.0. | |
7 | // | |
8 | // See accompanying file LICENSE_1_0.txt or copy at | |
9 | // http://www.boost.org/LICENSE_1_0.txt | |
10 | ||
11 | #include <boost/mp11/algorithm.hpp> | |
11fdf7f2 | 12 | #include <boost/mp11/utility.hpp> |
b32b8144 FG |
13 | #include <cstddef> |
14 | ||
15 | namespace boost | |
16 | { | |
17 | namespace mp11 | |
18 | { | |
19 | ||
20 | // mp_arg | |
21 | template<std::size_t I> struct mp_arg | |
22 | { | |
23 | template<class... T> using fn = mp_at_c<mp_list<T...>, I>; | |
24 | }; | |
25 | ||
26 | using _1 = mp_arg<0>; | |
27 | using _2 = mp_arg<1>; | |
28 | using _3 = mp_arg<2>; | |
29 | using _4 = mp_arg<3>; | |
30 | using _5 = mp_arg<4>; | |
31 | using _6 = mp_arg<5>; | |
32 | using _7 = mp_arg<6>; | |
33 | using _8 = mp_arg<7>; | |
34 | using _9 = mp_arg<8>; | |
35 | ||
36 | // mp_bind | |
37 | template<template<class...> class F, class... T> struct mp_bind; | |
38 | ||
39 | namespace detail | |
40 | { | |
41 | ||
42 | template<class V, class... T> struct eval_bound_arg | |
43 | { | |
44 | using type = V; | |
45 | }; | |
46 | ||
47 | template<std::size_t I, class... T> struct eval_bound_arg<mp_arg<I>, T...> | |
48 | { | |
49 | using type = typename mp_arg<I>::template fn<T...>; | |
50 | }; | |
51 | ||
52 | template<template<class...> class F, class... U, class... T> struct eval_bound_arg<mp_bind<F, U...>, T...> | |
53 | { | |
54 | using type = typename mp_bind<F, U...>::template fn<T...>; | |
55 | }; | |
56 | ||
57 | } // namespace detail | |
58 | ||
59 | template<template<class...> class F, class... T> struct mp_bind | |
60 | { | |
61 | template<class... U> using fn = F<typename detail::eval_bound_arg<T, U...>::type...>; | |
62 | }; | |
63 | ||
64 | template<class Q, class... T> using mp_bind_q = mp_bind<Q::template fn, T...>; | |
65 | ||
66 | // mp_bind_front | |
67 | template<template<class...> class F, class... T> struct mp_bind_front | |
68 | { | |
11fdf7f2 TL |
69 | // the indirection through mp_defer works around the language inability |
70 | // to expand U... into a fixed parameter list of an alias template | |
b32b8144 | 71 | |
11fdf7f2 | 72 | template<class... U> using fn = typename mp_defer<F, T..., U...>::type; |
b32b8144 FG |
73 | }; |
74 | ||
75 | template<class Q, class... T> using mp_bind_front_q = mp_bind_front<Q::template fn, T...>; | |
76 | ||
77 | // mp_bind_back | |
78 | template<template<class...> class F, class... T> struct mp_bind_back | |
79 | { | |
11fdf7f2 | 80 | template<class... U> using fn = typename mp_defer<F, U..., T...>::type; |
b32b8144 FG |
81 | }; |
82 | ||
83 | template<class Q, class... T> using mp_bind_back_q = mp_bind_back<Q::template fn, T...>; | |
84 | ||
85 | } // namespace mp11 | |
86 | } // namespace boost | |
87 | ||
88 | #endif // #ifndef BOOST_MP11_BIND_HPP_INCLUDED |