2 // Copyright 2000 John Maddock (john@johnmaddock.co.uk)
3 // Use, modification and distribution are subject to the Boost Software License,
4 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt).
7 // See http://www.boost.org/libs/type_traits for most recent version including documentation.
9 #ifndef BOOST_TT_FUNCTION_TRAITS_HPP_INCLUDED
10 #define BOOST_TT_FUNCTION_TRAITS_HPP_INCLUDED
12 #include <boost/config.hpp>
13 #include <boost/type_traits/is_function.hpp>
14 #include <boost/type_traits/add_pointer.hpp>
18 #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
21 template<typename Function> struct function_traits_helper;
24 struct function_traits_helper<R (*)(void)>
26 BOOST_STATIC_CONSTANT(int, arity = 0);
27 typedef R result_type;
30 template<typename R, typename T1>
31 struct function_traits_helper<R (*)(T1)>
33 BOOST_STATIC_CONSTANT(int, arity = 1);
34 typedef R result_type;
36 typedef T1 argument_type;
39 template<typename R, typename T1, typename T2>
40 struct function_traits_helper<R (*)(T1, T2)>
42 BOOST_STATIC_CONSTANT(int, arity = 2);
43 typedef R result_type;
46 typedef T1 first_argument_type;
47 typedef T2 second_argument_type;
50 template<typename R, typename T1, typename T2, typename T3>
51 struct function_traits_helper<R (*)(T1, T2, T3)>
53 BOOST_STATIC_CONSTANT(int, arity = 3);
54 typedef R result_type;
60 template<typename R, typename T1, typename T2, typename T3, typename T4>
61 struct function_traits_helper<R (*)(T1, T2, T3, T4)>
63 BOOST_STATIC_CONSTANT(int, arity = 4);
64 typedef R result_type;
71 template<typename R, typename T1, typename T2, typename T3, typename T4,
73 struct function_traits_helper<R (*)(T1, T2, T3, T4, T5)>
75 BOOST_STATIC_CONSTANT(int, arity = 5);
76 typedef R result_type;
84 template<typename R, typename T1, typename T2, typename T3, typename T4,
85 typename T5, typename T6>
86 struct function_traits_helper<R (*)(T1, T2, T3, T4, T5, T6)>
88 BOOST_STATIC_CONSTANT(int, arity = 6);
89 typedef R result_type;
98 template<typename R, typename T1, typename T2, typename T3, typename T4,
99 typename T5, typename T6, typename T7>
100 struct function_traits_helper<R (*)(T1, T2, T3, T4, T5, T6, T7)>
102 BOOST_STATIC_CONSTANT(int, arity = 7);
103 typedef R result_type;
104 typedef T1 arg1_type;
105 typedef T2 arg2_type;
106 typedef T3 arg3_type;
107 typedef T4 arg4_type;
108 typedef T5 arg5_type;
109 typedef T6 arg6_type;
110 typedef T7 arg7_type;
113 template<typename R, typename T1, typename T2, typename T3, typename T4,
114 typename T5, typename T6, typename T7, typename T8>
115 struct function_traits_helper<R (*)(T1, T2, T3, T4, T5, T6, T7, T8)>
117 BOOST_STATIC_CONSTANT(int, arity = 8);
118 typedef R result_type;
119 typedef T1 arg1_type;
120 typedef T2 arg2_type;
121 typedef T3 arg3_type;
122 typedef T4 arg4_type;
123 typedef T5 arg5_type;
124 typedef T6 arg6_type;
125 typedef T7 arg7_type;
126 typedef T8 arg8_type;
129 template<typename R, typename T1, typename T2, typename T3, typename T4,
130 typename T5, typename T6, typename T7, typename T8, typename T9>
131 struct function_traits_helper<R (*)(T1, T2, T3, T4, T5, T6, T7, T8, T9)>
133 BOOST_STATIC_CONSTANT(int, arity = 9);
134 typedef R result_type;
135 typedef T1 arg1_type;
136 typedef T2 arg2_type;
137 typedef T3 arg3_type;
138 typedef T4 arg4_type;
139 typedef T5 arg5_type;
140 typedef T6 arg6_type;
141 typedef T7 arg7_type;
142 typedef T8 arg8_type;
143 typedef T9 arg9_type;
146 template<typename R, typename T1, typename T2, typename T3, typename T4,
147 typename T5, typename T6, typename T7, typename T8, typename T9,
149 struct function_traits_helper<R (*)(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10)>
151 BOOST_STATIC_CONSTANT(int, arity = 10);
152 typedef R result_type;
153 typedef T1 arg1_type;
154 typedef T2 arg2_type;
155 typedef T3 arg3_type;
156 typedef T4 arg4_type;
157 typedef T5 arg5_type;
158 typedef T6 arg6_type;
159 typedef T7 arg7_type;
160 typedef T8 arg8_type;
161 typedef T9 arg9_type;
162 typedef T10 arg10_type;
165 } // end namespace detail
167 template<typename Function>
168 struct function_traits :
169 public detail::function_traits_helper<typename boost::add_pointer<Function>::type>
184 type_of_size<1> function_arity_helper(R (*f)());
186 template<typename R, typename T1>
187 type_of_size<2> function_arity_helper(R (*f)(T1));
189 template<typename R, typename T1, typename T2>
190 type_of_size<3> function_arity_helper(R (*f)(T1, T2));
192 template<typename R, typename T1, typename T2, typename T3>
193 type_of_size<4> function_arity_helper(R (*f)(T1, T2, T3));
195 template<typename R, typename T1, typename T2, typename T3, typename T4>
196 type_of_size<5> function_arity_helper(R (*f)(T1, T2, T3, T4));
198 template<typename R, typename T1, typename T2, typename T3, typename T4,
200 type_of_size<6> function_arity_helper(R (*f)(T1, T2, T3, T4, T5));
202 template<typename R, typename T1, typename T2, typename T3, typename T4,
203 typename T5, typename T6>
204 type_of_size<7> function_arity_helper(R (*f)(T1, T2, T3, T4, T5, T6));
206 template<typename R, typename T1, typename T2, typename T3, typename T4,
207 typename T5, typename T6, typename T7>
208 type_of_size<8> function_arity_helper(R (*f)(T1, T2, T3, T4, T5, T6, T7));
210 template<typename R, typename T1, typename T2, typename T3, typename T4,
211 typename T5, typename T6, typename T7, typename T8>
212 type_of_size<9> function_arity_helper(R (*f)(T1, T2, T3, T4, T5, T6, T7, T8));
214 template<typename R, typename T1, typename T2, typename T3, typename T4,
215 typename T5, typename T6, typename T7, typename T8, typename T9>
216 type_of_size<10> function_arity_helper(R (*f)(T1, T2, T3, T4, T5, T6, T7, T8,
219 template<typename R, typename T1, typename T2, typename T3, typename T4,
220 typename T5, typename T6, typename T7, typename T8, typename T9,
222 type_of_size<11> function_arity_helper(R (*f)(T1, T2, T3, T4, T5, T6, T7, T8,
224 } // end namespace detail
226 // Won't work with references
227 template<typename Function>
228 struct function_traits
230 BOOST_STATIC_CONSTANT(int, arity = (sizeof(detail::function_arity_helper((Function*)0))-1));
233 #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
236 #endif // BOOST_TT_FUNCTION_TRAITS_HPP_INCLUDED