function_traits.hpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. // Copyright 2000 John Maddock (john@johnmaddock.co.uk)
  2. // Use, modification and distribution are subject to the Boost Software License,
  3. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt).
  5. //
  6. // See http://www.boost.org/libs/type_traits for most recent version including documentation.
  7. #ifndef BOOST_TT_FUNCTION_TRAITS_HPP_INCLUDED
  8. #define BOOST_TT_FUNCTION_TRAITS_HPP_INCLUDED
  9. #include <boost/config.hpp>
  10. #include <boost/type_traits/is_function.hpp>
  11. #include <boost/type_traits/add_pointer.hpp>
  12. namespace boost {
  13. namespace detail {
  14. template<typename Function> struct function_traits_helper;
  15. template<typename R>
  16. struct function_traits_helper<R (*)(void)>
  17. {
  18. BOOST_STATIC_CONSTANT(unsigned, arity = 0);
  19. typedef R result_type;
  20. };
  21. template<typename R, typename T1>
  22. struct function_traits_helper<R (*)(T1)>
  23. {
  24. BOOST_STATIC_CONSTANT(unsigned, arity = 1);
  25. typedef R result_type;
  26. typedef T1 arg1_type;
  27. typedef T1 argument_type;
  28. };
  29. template<typename R, typename T1, typename T2>
  30. struct function_traits_helper<R (*)(T1, T2)>
  31. {
  32. BOOST_STATIC_CONSTANT(unsigned, arity = 2);
  33. typedef R result_type;
  34. typedef T1 arg1_type;
  35. typedef T2 arg2_type;
  36. typedef T1 first_argument_type;
  37. typedef T2 second_argument_type;
  38. };
  39. template<typename R, typename T1, typename T2, typename T3>
  40. struct function_traits_helper<R (*)(T1, T2, T3)>
  41. {
  42. BOOST_STATIC_CONSTANT(unsigned, arity = 3);
  43. typedef R result_type;
  44. typedef T1 arg1_type;
  45. typedef T2 arg2_type;
  46. typedef T3 arg3_type;
  47. };
  48. template<typename R, typename T1, typename T2, typename T3, typename T4>
  49. struct function_traits_helper<R (*)(T1, T2, T3, T4)>
  50. {
  51. BOOST_STATIC_CONSTANT(unsigned, arity = 4);
  52. typedef R result_type;
  53. typedef T1 arg1_type;
  54. typedef T2 arg2_type;
  55. typedef T3 arg3_type;
  56. typedef T4 arg4_type;
  57. };
  58. template<typename R, typename T1, typename T2, typename T3, typename T4,
  59. typename T5>
  60. struct function_traits_helper<R (*)(T1, T2, T3, T4, T5)>
  61. {
  62. BOOST_STATIC_CONSTANT(unsigned, arity = 5);
  63. typedef R result_type;
  64. typedef T1 arg1_type;
  65. typedef T2 arg2_type;
  66. typedef T3 arg3_type;
  67. typedef T4 arg4_type;
  68. typedef T5 arg5_type;
  69. };
  70. template<typename R, typename T1, typename T2, typename T3, typename T4,
  71. typename T5, typename T6>
  72. struct function_traits_helper<R (*)(T1, T2, T3, T4, T5, T6)>
  73. {
  74. BOOST_STATIC_CONSTANT(unsigned, arity = 6);
  75. typedef R result_type;
  76. typedef T1 arg1_type;
  77. typedef T2 arg2_type;
  78. typedef T3 arg3_type;
  79. typedef T4 arg4_type;
  80. typedef T5 arg5_type;
  81. typedef T6 arg6_type;
  82. };
  83. template<typename R, typename T1, typename T2, typename T3, typename T4,
  84. typename T5, typename T6, typename T7>
  85. struct function_traits_helper<R (*)(T1, T2, T3, T4, T5, T6, T7)>
  86. {
  87. BOOST_STATIC_CONSTANT(unsigned, arity = 7);
  88. typedef R result_type;
  89. typedef T1 arg1_type;
  90. typedef T2 arg2_type;
  91. typedef T3 arg3_type;
  92. typedef T4 arg4_type;
  93. typedef T5 arg5_type;
  94. typedef T6 arg6_type;
  95. typedef T7 arg7_type;
  96. };
  97. template<typename R, typename T1, typename T2, typename T3, typename T4,
  98. typename T5, typename T6, typename T7, typename T8>
  99. struct function_traits_helper<R (*)(T1, T2, T3, T4, T5, T6, T7, T8)>
  100. {
  101. BOOST_STATIC_CONSTANT(unsigned, arity = 8);
  102. typedef R result_type;
  103. typedef T1 arg1_type;
  104. typedef T2 arg2_type;
  105. typedef T3 arg3_type;
  106. typedef T4 arg4_type;
  107. typedef T5 arg5_type;
  108. typedef T6 arg6_type;
  109. typedef T7 arg7_type;
  110. typedef T8 arg8_type;
  111. };
  112. template<typename R, typename T1, typename T2, typename T3, typename T4,
  113. typename T5, typename T6, typename T7, typename T8, typename T9>
  114. struct function_traits_helper<R (*)(T1, T2, T3, T4, T5, T6, T7, T8, T9)>
  115. {
  116. BOOST_STATIC_CONSTANT(unsigned, arity = 9);
  117. typedef R result_type;
  118. typedef T1 arg1_type;
  119. typedef T2 arg2_type;
  120. typedef T3 arg3_type;
  121. typedef T4 arg4_type;
  122. typedef T5 arg5_type;
  123. typedef T6 arg6_type;
  124. typedef T7 arg7_type;
  125. typedef T8 arg8_type;
  126. typedef T9 arg9_type;
  127. };
  128. template<typename R, typename T1, typename T2, typename T3, typename T4,
  129. typename T5, typename T6, typename T7, typename T8, typename T9,
  130. typename T10>
  131. struct function_traits_helper<R (*)(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10)>
  132. {
  133. BOOST_STATIC_CONSTANT(unsigned, arity = 10);
  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;
  144. typedef T10 arg10_type;
  145. };
  146. } // end namespace detail
  147. template<typename Function>
  148. struct function_traits :
  149. public boost::detail::function_traits_helper<typename boost::add_pointer<Function>::type>
  150. {
  151. };
  152. }
  153. #endif // BOOST_TT_FUNCTION_TRAITS_HPP_INCLUDED