// Copyright (C) 2000 John Maddock (john_maddock@compuserve.com) // // Permission to copy and use this software is granted, // provided this copyright notice appears in all copies. // Permission to modify the code and to distribute modified code is granted, // provided this copyright notice appears in all copies, and a notice // that the code was modified is included with the copyright notice. // // This software is provided "as is" without express or implied warranty, // and with no claim as to its suitability for any purpose. #ifndef BOOST_TT_FUNCTION_TRAITS_HPP_INCLUDED #define BOOST_TT_FUNCTION_TRAITS_HPP_INCLUDED #include #include #include namespace boost { #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION namespace detail { template struct function_traits_helper; template struct function_traits_helper { BOOST_STATIC_CONSTANT(int, arity = 0); typedef R result_type; }; template struct function_traits_helper { BOOST_STATIC_CONSTANT(int, arity = 1); typedef R result_type; typedef T1 arg1_type; }; template struct function_traits_helper { BOOST_STATIC_CONSTANT(int, arity = 2); typedef R result_type; typedef T1 arg1_type; typedef T2 arg2_type; }; template struct function_traits_helper { BOOST_STATIC_CONSTANT(int, arity = 3); typedef R result_type; typedef T1 arg1_type; typedef T2 arg2_type; typedef T3 arg3_type; }; template struct function_traits_helper { BOOST_STATIC_CONSTANT(int, arity = 4); typedef R result_type; typedef T1 arg1_type; typedef T2 arg2_type; typedef T3 arg3_type; typedef T4 arg4_type; }; template struct function_traits_helper { BOOST_STATIC_CONSTANT(int, arity = 5); typedef R result_type; typedef T1 arg1_type; typedef T2 arg2_type; typedef T3 arg3_type; typedef T4 arg4_type; typedef T5 arg5_type; }; template struct function_traits_helper { BOOST_STATIC_CONSTANT(int, arity = 6); typedef R result_type; typedef T1 arg1_type; typedef T2 arg2_type; typedef T3 arg3_type; typedef T4 arg4_type; typedef T5 arg5_type; typedef T6 arg6_type; }; template struct function_traits_helper { BOOST_STATIC_CONSTANT(int, arity = 7); typedef R result_type; typedef T1 arg1_type; typedef T2 arg2_type; typedef T3 arg3_type; typedef T4 arg4_type; typedef T5 arg5_type; typedef T6 arg6_type; typedef T7 arg7_type; }; template struct function_traits_helper { BOOST_STATIC_CONSTANT(int, arity = 8); typedef R result_type; typedef T1 arg1_type; typedef T2 arg2_type; typedef T3 arg3_type; typedef T4 arg4_type; typedef T5 arg5_type; typedef T6 arg6_type; typedef T7 arg7_type; typedef T8 arg8_type; }; template struct function_traits_helper { BOOST_STATIC_CONSTANT(int, arity = 9); typedef R result_type; typedef T1 arg1_type; typedef T2 arg2_type; typedef T3 arg3_type; typedef T4 arg4_type; typedef T5 arg5_type; typedef T6 arg6_type; typedef T7 arg7_type; typedef T8 arg8_type; typedef T9 arg9_type; }; template struct function_traits_helper { BOOST_STATIC_CONSTANT(int, arity = 10); typedef R result_type; typedef T1 arg1_type; typedef T2 arg2_type; typedef T3 arg3_type; typedef T4 arg4_type; typedef T5 arg5_type; typedef T6 arg6_type; typedef T7 arg7_type; typedef T8 arg8_type; typedef T9 arg9_type; typedef T10 arg10_type; }; template struct function_traits_helper { BOOST_STATIC_CONSTANT(int, arity = 0); typedef Class class_type; typedef R result_type; }; template struct function_traits_helper { BOOST_STATIC_CONSTANT(int, arity = 1); typedef Class class_type; typedef R result_type; typedef T1 arg1_type; }; template struct function_traits_helper { BOOST_STATIC_CONSTANT(int, arity = 2); typedef R result_type; typedef T1 arg1_type; typedef T2 arg2_type; typedef Class class_type; }; template struct function_traits_helper { BOOST_STATIC_CONSTANT(int, arity = 3); typedef R result_type; typedef T1 arg1_type; typedef T2 arg2_type; typedef T3 arg3_type; typedef Class class_type; }; template struct function_traits_helper { BOOST_STATIC_CONSTANT(int, arity = 4); typedef R result_type; typedef T1 arg1_type; typedef T2 arg2_type; typedef T3 arg3_type; typedef T4 arg4_type; typedef Class class_type; }; template struct function_traits_helper { BOOST_STATIC_CONSTANT(int, arity = 5); typedef R result_type; typedef T1 arg1_type; typedef T2 arg2_type; typedef T3 arg3_type; typedef T4 arg4_type; typedef T5 arg5_type; typedef Class class_type; }; template struct function_traits_helper { BOOST_STATIC_CONSTANT(int, arity = 6); typedef R result_type; typedef T1 arg1_type; typedef T2 arg2_type; typedef T3 arg3_type; typedef T4 arg4_type; typedef T5 arg5_type; typedef T6 arg6_type; typedef Class class_type; }; template struct function_traits_helper { BOOST_STATIC_CONSTANT(int, arity = 7); typedef R result_type; typedef T1 arg1_type; typedef T2 arg2_type; typedef T3 arg3_type; typedef T4 arg4_type; typedef T5 arg5_type; typedef T6 arg6_type; typedef T7 arg7_type; typedef Class class_type; }; template struct function_traits_helper { BOOST_STATIC_CONSTANT(int, arity = 8); typedef R result_type; typedef T1 arg1_type; typedef T2 arg2_type; typedef T3 arg3_type; typedef T4 arg4_type; typedef T5 arg5_type; typedef T6 arg6_type; typedef T7 arg7_type; typedef T8 arg8_type; typedef Class class_type; }; template struct function_traits_helper { BOOST_STATIC_CONSTANT(int, arity = 9); typedef R result_type; typedef T1 arg1_type; typedef T2 arg2_type; typedef T3 arg3_type; typedef T4 arg4_type; typedef T5 arg5_type; typedef T6 arg6_type; typedef T7 arg7_type; typedef T8 arg8_type; typedef T9 arg9_type; typedef Class class_type; }; template struct function_traits_helper { BOOST_STATIC_CONSTANT(int, arity = 10); typedef R result_type; typedef T1 arg1_type; typedef T2 arg2_type; typedef T3 arg3_type; typedef T4 arg4_type; typedef T5 arg5_type; typedef T6 arg6_type; typedef T7 arg7_type; typedef T8 arg8_type; typedef T9 arg9_type; typedef T10 arg10_type; typedef Class class_type; }; } // end namespace detail template struct function_traits : public detail::function_traits_helper::type> { }; #else namespace detail { template struct type_of_size { char elements[N]; }; template type_of_size<1> function_arity_helper(R (*f)()); template type_of_size<2> function_arity_helper(R (*f)(T1)); template type_of_size<3> function_arity_helper(R (*f)(T1, T2)); template type_of_size<4> function_arity_helper(R (*f)(T1, T2, T3)); template type_of_size<5> function_arity_helper(R (*f)(T1, T2, T3, T4)); template type_of_size<6> function_arity_helper(R (*f)(T1, T2, T3, T4, T5)); template type_of_size<7> function_arity_helper(R (*f)(T1, T2, T3, T4, T5, T6)); template type_of_size<8> function_arity_helper(R (*f)(T1, T2, T3, T4, T5, T6, T7)); template type_of_size<9> function_arity_helper(R (*f)(T1, T2, T3, T4, T5, T6, T7, T8)); template type_of_size<10> function_arity_helper(R (*f)(T1, T2, T3, T4, T5, T6, T7, T8, T9)); template type_of_size<11> function_arity_helper(R (*f)(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10)); template type_of_size<1> function_arity_helper(R (Class::*f)()); template type_of_size<2> function_arity_helper(R (Class::*f)(T1)); template type_of_size<3> function_arity_helper(R (Class::*f)(T1, T2)); template type_of_size<4> function_arity_helper(R (Class::*f)(T1, T2, T3)); template type_of_size<5> function_arity_helper(R (Class::*f)(T1, T2, T3, T4)); template type_of_size<6> function_arity_helper(R (Class::*f)(T1, T2, T3, T4, T5)); template type_of_size<7> function_arity_helper(R (Class::*f)(T1, T2, T3, T4, T5, T6)); template type_of_size<8> function_arity_helper(R (Class::*f)(T1, T2, T3, T4, T5, T6, T7)); template type_of_size<9> function_arity_helper(R (Class::*f)(T1, T2, T3, T4, T5, T6, T7, T8)); template type_of_size<10> function_arity_helper(R (Class::*f)(T1, T2, T3, T4, T5, T6, T7, T8, T9)); template type_of_size<11> function_arity_helper(R (Class::*f)(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10)); } // end namespace detail // Won't work with references template struct function_traits { BOOST_STATIC_CONSTANT(int, arity = (sizeof(detail::function_arity_helper((Function*)0))-1)); }; #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION } #endif // BOOST_TT_FUNCTION_TRAITS_HPP_INCLUDED