1#ifndef BOOST_MP11_BIND_HPP_INCLUDED
2#define BOOST_MP11_BIND_HPP_INCLUDED
3
4// Copyright 2017, 2018 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>
12#include <boost/mp11/utility.hpp>
13#include <cstddef>
14
15namespace boost
16{
17namespace mp11
18{
19
20// mp_bind_front
21template<template<class...> class F, class... T> struct mp_bind_front
22{
23 // the indirection through mp_defer works around the language inability
24 // to expand U... into a fixed parameter list of an alias template
25
26 template<class... U> using fn = typename mp_defer<F, T..., U...>::type;
27};
28
29template<class Q, class... T> using mp_bind_front_q = mp_bind_front<Q::template fn, T...>;
30
31// mp_bind_back
32template<template<class...> class F, class... T> struct mp_bind_back
33{
34 template<class... U> using fn = typename mp_defer<F, U..., T...>::type;
35};
36
37template<class Q, class... T> using mp_bind_back_q = mp_bind_back<Q::template fn, T...>;
38
39// mp_arg
40template<std::size_t I> struct mp_arg
41{
42 template<class... T> using fn = mp_at_c<mp_list<T...>, I>;
43};
44
45using _1 = mp_arg<0>;
46using _2 = mp_arg<1>;
47using _3 = mp_arg<2>;
48using _4 = mp_arg<3>;
49using _5 = mp_arg<4>;
50using _6 = mp_arg<5>;
51using _7 = mp_arg<6>;
52using _8 = mp_arg<7>;
53using _9 = mp_arg<8>;
54
55// mp_bind
56template<template<class...> class F, class... T> struct mp_bind;
57
58namespace detail
59{
60
61template<class V, class... T> struct eval_bound_arg
62{
63 using type = V;
64};
65
66template<std::size_t I, class... T> struct eval_bound_arg<mp_arg<I>, T...>
67{
68 using type = typename mp_arg<I>::template fn<T...>;
69};
70
71template<template<class...> class F, class... U, class... T> struct eval_bound_arg<mp_bind<F, U...>, T...>
72{
73 using type = typename mp_bind<F, U...>::template fn<T...>;
74};
75
76template<template<class...> class F, class... U, class... T> struct eval_bound_arg<mp_bind_front<F, U...>, T...>
77{
78 using type = typename mp_bind_front<F, U...>::template fn<T...>;
79};
80
81template<template<class...> class F, class... U, class... T> struct eval_bound_arg<mp_bind_back<F, U...>, T...>
82{
83 using type = typename mp_bind_back<F, U...>::template fn<T...>;
84};
85
86} // namespace detail
87
88template<template<class...> class F, class... T> struct mp_bind
89{
90#if BOOST_MP11_WORKAROUND( BOOST_MP11_MSVC, == 1915 )
91private:
92
93 template<class... U> struct _f { using type = F<typename detail::eval_bound_arg<T, U...>::type...>; };
94
95public:
96
97 template<class... U> using fn = typename _f<U...>::type;
98
99#else
100
101 template<class... U> using fn = F<typename detail::eval_bound_arg<T, U...>::type...>;
102
103#endif
104};
105
106template<class Q, class... T> using mp_bind_q = mp_bind<Q::template fn, T...>;
107
108} // namespace mp11
109} // namespace boost
110
111#endif // #ifndef BOOST_MP11_BIND_HPP_INCLUDED
112

source code of include/boost/mp11/bind.hpp