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

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