]> git.lyx.org Git - lyx.git/blob - boost/boost/type_traits/function_traits.hpp
Bug: 935
[lyx.git] / boost / boost / type_traits / function_traits.hpp
1
2 // Copyright (C) 2000 John Maddock (john_maddock@compuserve.com)
3 //
4 // Permission to copy and use this software is granted, 
5 // provided this copyright notice appears in all copies. 
6 // Permission to modify the code and to distribute modified code is granted, 
7 // provided this copyright notice appears in all copies, and a notice 
8 // that the code was modified is included with the copyright notice.
9 //
10 // This software is provided "as is" without express or implied warranty, 
11 // and with no claim as to its suitability for any purpose.
12
13 #ifndef BOOST_TT_FUNCTION_TRAITS_HPP_INCLUDED
14 #define BOOST_TT_FUNCTION_TRAITS_HPP_INCLUDED
15
16 #include <boost/config.hpp>
17 #include <boost/type_traits/is_function.hpp>
18 #include <boost/type_traits/add_pointer.hpp>
19
20 namespace boost {
21
22 #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
23 namespace detail {
24
25 template<typename Function> struct function_traits_helper;
26
27 template<typename R>
28 struct function_traits_helper<R (*)(void)>
29 {
30   BOOST_STATIC_CONSTANT(int, arity = 0);
31   typedef R result_type;
32 };
33
34 template<typename R, typename T1>
35 struct function_traits_helper<R (*)(T1)>
36 {
37   BOOST_STATIC_CONSTANT(int, arity = 1);
38   typedef R result_type;
39   typedef T1 arg1_type;
40 };
41
42 template<typename R, typename T1, typename T2>
43 struct function_traits_helper<R (*)(T1, T2)>
44 {
45   BOOST_STATIC_CONSTANT(int, arity = 2);
46   typedef R result_type;
47   typedef T1 arg1_type;
48   typedef T2 arg2_type;
49 };
50
51 template<typename R, typename T1, typename T2, typename T3>
52 struct function_traits_helper<R (*)(T1, T2, T3)>
53 {
54   BOOST_STATIC_CONSTANT(int, arity = 3);
55   typedef R result_type;
56   typedef T1 arg1_type;
57   typedef T2 arg2_type;
58   typedef T3 arg3_type;
59 };
60
61 template<typename R, typename T1, typename T2, typename T3, typename T4>
62 struct function_traits_helper<R (*)(T1, T2, T3, T4)>
63 {
64   BOOST_STATIC_CONSTANT(int, arity = 4);
65   typedef R result_type;
66   typedef T1 arg1_type;
67   typedef T2 arg2_type;
68   typedef T3 arg3_type;
69   typedef T4 arg4_type;
70 };
71
72 template<typename R, typename T1, typename T2, typename T3, typename T4,
73          typename T5>
74 struct function_traits_helper<R (*)(T1, T2, T3, T4, T5)>
75 {
76   BOOST_STATIC_CONSTANT(int, arity = 5);
77   typedef R result_type;
78   typedef T1 arg1_type;
79   typedef T2 arg2_type;
80   typedef T3 arg3_type;
81   typedef T4 arg4_type;
82   typedef T5 arg5_type;
83 };
84
85 template<typename R, typename T1, typename T2, typename T3, typename T4,
86          typename T5, typename T6>
87 struct function_traits_helper<R (*)(T1, T2, T3, T4, T5, T6)>
88 {
89   BOOST_STATIC_CONSTANT(int, arity = 6);
90   typedef R result_type;
91   typedef T1 arg1_type;
92   typedef T2 arg2_type;
93   typedef T3 arg3_type;
94   typedef T4 arg4_type;
95   typedef T5 arg5_type;
96   typedef T6 arg6_type;
97 };
98
99 template<typename R, typename T1, typename T2, typename T3, typename T4,
100          typename T5, typename T6, typename T7>
101 struct function_traits_helper<R (*)(T1, T2, T3, T4, T5, T6, T7)>
102 {
103   BOOST_STATIC_CONSTANT(int, arity = 7);
104   typedef R result_type;
105   typedef T1 arg1_type;
106   typedef T2 arg2_type;
107   typedef T3 arg3_type;
108   typedef T4 arg4_type;
109   typedef T5 arg5_type;
110   typedef T6 arg6_type;
111   typedef T7 arg7_type;
112 };
113
114 template<typename R, typename T1, typename T2, typename T3, typename T4,
115          typename T5, typename T6, typename T7, typename T8>
116 struct function_traits_helper<R (*)(T1, T2, T3, T4, T5, T6, T7, T8)>
117 {
118   BOOST_STATIC_CONSTANT(int, arity = 8);
119   typedef R result_type;
120   typedef T1 arg1_type;
121   typedef T2 arg2_type;
122   typedef T3 arg3_type;
123   typedef T4 arg4_type;
124   typedef T5 arg5_type;
125   typedef T6 arg6_type;
126   typedef T7 arg7_type;
127   typedef T8 arg8_type;
128 };
129
130 template<typename R, typename T1, typename T2, typename T3, typename T4,
131          typename T5, typename T6, typename T7, typename T8, typename T9>
132 struct function_traits_helper<R (*)(T1, T2, T3, T4, T5, T6, T7, T8, T9)>
133 {
134   BOOST_STATIC_CONSTANT(int, arity = 9);
135   typedef R result_type;
136   typedef T1 arg1_type;
137   typedef T2 arg2_type;
138   typedef T3 arg3_type;
139   typedef T4 arg4_type;
140   typedef T5 arg5_type;
141   typedef T6 arg6_type;
142   typedef T7 arg7_type;
143   typedef T8 arg8_type;
144   typedef T9 arg9_type;
145 };
146
147 template<typename R, typename T1, typename T2, typename T3, typename T4,
148          typename T5, typename T6, typename T7, typename T8, typename T9,
149          typename T10>
150 struct function_traits_helper<R (*)(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10)>
151 {
152   BOOST_STATIC_CONSTANT(int, arity = 10);
153   typedef R result_type;
154   typedef T1 arg1_type;
155   typedef T2 arg2_type;
156   typedef T3 arg3_type;
157   typedef T4 arg4_type;
158   typedef T5 arg5_type;
159   typedef T6 arg6_type;
160   typedef T7 arg7_type;
161   typedef T8 arg8_type;
162   typedef T9 arg9_type;
163   typedef T10 arg10_type;
164 };
165
166 } // end namespace detail
167
168 template<typename Function>
169 struct function_traits : 
170     public detail::function_traits_helper<typename add_pointer<Function>::type>
171 {
172 };
173
174 #else
175
176 namespace detail {
177
178 template<int N> 
179 struct type_of_size
180 {
181   char elements[N];
182 };
183
184 template<typename R>
185 type_of_size<1> function_arity_helper(R (*f)());
186
187 template<typename R, typename T1>
188 type_of_size<2> function_arity_helper(R (*f)(T1));
189
190 template<typename R, typename T1, typename T2>
191 type_of_size<3> function_arity_helper(R (*f)(T1, T2));
192
193 template<typename R, typename T1, typename T2, typename T3>
194 type_of_size<4> function_arity_helper(R (*f)(T1, T2, T3));
195
196 template<typename R, typename T1, typename T2, typename T3, typename T4>
197 type_of_size<5> function_arity_helper(R (*f)(T1, T2, T3, T4));
198
199 template<typename R, typename T1, typename T2, typename T3, typename T4,
200          typename T5>
201 type_of_size<6> function_arity_helper(R (*f)(T1, T2, T3, T4, T5));
202
203 template<typename R, typename T1, typename T2, typename T3, typename T4,
204          typename T5, typename T6>
205 type_of_size<7> function_arity_helper(R (*f)(T1, T2, T3, T4, T5, T6));
206
207 template<typename R, typename T1, typename T2, typename T3, typename T4,
208          typename T5, typename T6, typename T7>
209 type_of_size<8> function_arity_helper(R (*f)(T1, T2, T3, T4, T5, T6, T7));
210
211 template<typename R, typename T1, typename T2, typename T3, typename T4,
212          typename T5, typename T6, typename T7, typename T8>
213 type_of_size<9> function_arity_helper(R (*f)(T1, T2, T3, T4, T5, T6, T7, T8));
214
215 template<typename R, typename T1, typename T2, typename T3, typename T4,
216          typename T5, typename T6, typename T7, typename T8, typename T9>
217 type_of_size<10> function_arity_helper(R (*f)(T1, T2, T3, T4, T5, T6, T7, T8, 
218                                               T9));
219
220 template<typename R, typename T1, typename T2, typename T3, typename T4,
221          typename T5, typename T6, typename T7, typename T8, typename T9,
222          typename T10>
223 type_of_size<11> function_arity_helper(R (*f)(T1, T2, T3, T4, T5, T6, T7, T8, 
224                                               T9, T10));
225 } // end namespace detail
226
227 // Won't work with references
228 template<typename Function>
229 struct function_traits
230 {
231   BOOST_STATIC_CONSTANT(int, arity = (sizeof(detail::function_arity_helper((Function*)0))-1));
232 };
233
234 #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
235 }
236
237 #endif // BOOST_TT_FUNCTION_TRAITS_HPP_INCLUDED