fix doc example typo
[boost.git] / boost / type_traits / function_traits.hpp
blobbfc3f7e53b2d5fb03d2aa1650555d401265f734d
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).
6 //
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>
16 namespace boost {
18 #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
19 namespace detail {
21 template<typename Function> struct function_traits_helper;
23 template<typename R>
24 struct function_traits_helper<R (*)(void)>
26 BOOST_STATIC_CONSTANT(unsigned, arity = 0);
27 typedef R result_type;
30 template<typename R, typename T1>
31 struct function_traits_helper<R (*)(T1)>
33 BOOST_STATIC_CONSTANT(unsigned, arity = 1);
34 typedef R result_type;
35 typedef T1 arg1_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(unsigned, arity = 2);
43 typedef R result_type;
44 typedef T1 arg1_type;
45 typedef T2 arg2_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(unsigned, arity = 3);
54 typedef R result_type;
55 typedef T1 arg1_type;
56 typedef T2 arg2_type;
57 typedef T3 arg3_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(unsigned, arity = 4);
64 typedef R result_type;
65 typedef T1 arg1_type;
66 typedef T2 arg2_type;
67 typedef T3 arg3_type;
68 typedef T4 arg4_type;
71 template<typename R, typename T1, typename T2, typename T3, typename T4,
72 typename T5>
73 struct function_traits_helper<R (*)(T1, T2, T3, T4, T5)>
75 BOOST_STATIC_CONSTANT(unsigned, arity = 5);
76 typedef R result_type;
77 typedef T1 arg1_type;
78 typedef T2 arg2_type;
79 typedef T3 arg3_type;
80 typedef T4 arg4_type;
81 typedef T5 arg5_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(unsigned, arity = 6);
89 typedef R result_type;
90 typedef T1 arg1_type;
91 typedef T2 arg2_type;
92 typedef T3 arg3_type;
93 typedef T4 arg4_type;
94 typedef T5 arg5_type;
95 typedef T6 arg6_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(unsigned, 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(unsigned, 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(unsigned, 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,
148 typename T10>
149 struct function_traits_helper<R (*)(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10)>
151 BOOST_STATIC_CONSTANT(unsigned, 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>
173 #else
175 namespace detail {
177 template<unsigned N>
178 struct type_of_size
180 char elements[N];
183 template<typename R>
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,
199 typename T5>
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,
217 T9));
219 template<typename R, typename T1, typename T2, typename T3, typename T4,
220 typename T5, typename T6, typename T7, typename T8, typename T9,
221 typename T10>
222 type_of_size<11> function_arity_helper(R (*f)(T1, T2, T3, T4, T5, T6, T7, T8,
223 T9, T10));
224 } // end namespace detail
226 // Won't work with references
227 template<typename Function>
228 struct function_traits
230 BOOST_STATIC_CONSTANT(unsigned, arity = (sizeof(detail::function_arity_helper((Function*)0))-1));
233 #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
236 #endif // BOOST_TT_FUNCTION_TRAITS_HPP_INCLUDED