]> git.lyx.org Git - lyx.git/blob - boost/boost/bind/make_adaptable.hpp
update boost
[lyx.git] / boost / boost / bind / make_adaptable.hpp
1 #ifndef BOOST_BIND_MAKE_ADAPTABLE_HPP_INCLUDED
2 #define BOOST_BIND_MAKE_ADAPTABLE_HPP_INCLUDED
3
4 //
5 //  make_adaptable.hpp
6 //
7 //  Copyright (c) 2002 Peter Dimov and Multi Media Ltd.
8 //
9 //  Permission to copy, use, modify, sell and distribute this software
10 //  is granted provided this copyright notice appears in all copies.
11 //  This software is provided "as is" without express or implied
12 //  warranty, and with no claim as to its suitability for any purpose.
13 //
14
15 namespace boost
16 {
17
18 namespace _bi
19 {
20
21 template<class F> void instantiate(F)
22 {
23 }
24
25 template<class R, class F> class af0
26 {
27 public:
28
29     typedef R result_type;
30
31     explicit af0(F f): f_(f)
32     {
33     }
34
35     result_type operator()()
36     {
37         return f_();
38     }
39
40 private:
41
42     F f_;
43 };
44
45 template<class R, class A1, class F> class af1
46 {
47 public:
48
49     typedef R result_type;
50     typedef A1 argument_type;
51     typedef A1 arg1_type;
52
53     explicit af1(F f): f_(f)
54     {
55     }
56
57     result_type operator()(A1 a1)
58     {
59         return f_(a1);
60     }
61
62 private:
63
64     F f_;
65 };
66
67 template<class R, class A1, class A2, class F> class af2
68 {
69 public:
70
71     typedef R result_type;
72     typedef A1 first_argument_type;
73     typedef A2 second_argument_type;
74     typedef A1 arg1_type;
75     typedef A2 arg2_type;
76
77     explicit af2(F f): f_(f)
78     {
79     }
80
81     result_type operator()(A1 a1, A2 a2)
82     {
83         return f_(a1, a2);
84     }
85
86 private:
87
88     F f_;
89 };
90
91 template<class R, class A1, class A2, class A3, class F> class af3
92 {
93 public:
94
95     typedef R result_type;
96     typedef A1 arg1_type;
97     typedef A2 arg2_type;
98     typedef A3 arg3_type;
99
100     explicit af3(F f): f_(f)
101     {
102     }
103
104     result_type operator()(A1 a1, A2 a2, A3 a3)
105     {
106         return f_(a1, a2, a3);
107     }
108
109 private:
110
111     F f_;
112 };
113
114 template<class R, class A1, class A2, class A3, class A4, class F> class af4
115 {
116 public:
117
118     typedef R result_type;
119     typedef A1 arg1_type;
120     typedef A2 arg2_type;
121     typedef A3 arg3_type;
122     typedef A4 arg4_type;
123
124     explicit af4(F f): f_(f)
125     {
126     }
127
128     result_type operator()(A1 a1, A2 a2, A3 a3, A4 a4)
129     {
130         return f_(a1, a2, a3, a4);
131     }
132
133 private:
134
135     F f_;
136 };
137
138 } // namespace _bi
139
140 template<class R, class F> _bi::af0<R, F> make_adaptable(F f)
141 {
142     _bi::instantiate( &_bi::af0<R, F>::operator() ); // for early error detection
143     return _bi::af0<R, F>(f);
144 }
145
146 template<class R, class A1, class F> _bi::af1<R, A1, F> make_adaptable(F f)
147 {
148     instantiate( &_bi::af1<R, A1, F>::operator() );
149     return _bi::af1<R, A1, F>(f);
150 }
151
152 template<class R, class A1, class A2, class F> _bi::af2<R, A1, A2, F> make_adaptable(F f)
153 {
154     instantiate( &_bi::af2<R, A1, A2, F>::operator() );
155     return _bi::af2<R, A1, A2, F>(f);
156 }
157
158 template<class R, class A1, class A2, class A3, class F> _bi::af3<R, A1, A2, A3, F> make_adaptable(F f)
159 {
160     instantiate( &_bi::af3<R, A1, A2, A3, F>::operator() );
161     return _bi::af3<R, A1, A2, A3, F>(f);
162 }
163
164 template<class R, class A1, class A2, class A3, class A4, class F> _bi::af4<R, A1, A2, A3, A4, F> make_adaptable(F f)
165 {
166     instantiate( &_bi::af4<R, A1, A2, A3, A4, F>::operator() );
167     return _bi::af4<R, A1, A2, A3, A4, F>(f);
168 }
169
170 } // namespace boost
171
172 #endif // #ifndef BOOST_BIND_MAKE_ADAPTABLE_HPP_INCLUDED