forked from boostorg/type_traits
Add support for retrieving the arity of a function type without partial
specialization. Document and test this [SVN r14694]
This commit is contained in:
@ -300,6 +300,66 @@ struct function_traits :
|
||||
{
|
||||
};
|
||||
|
||||
#else
|
||||
|
||||
namespace detail {
|
||||
|
||||
template<int N>
|
||||
struct type_of_size
|
||||
{
|
||||
char elements[N];
|
||||
};
|
||||
|
||||
template<typename R>
|
||||
type_of_size<1> function_arity_helper(R (*f)());
|
||||
|
||||
template<typename R, typename T1>
|
||||
type_of_size<2> function_arity_helper(R (*f)(T1));
|
||||
|
||||
template<typename R, typename T1, typename T2>
|
||||
type_of_size<3> function_arity_helper(R (*f)(T1, T2));
|
||||
|
||||
template<typename R, typename T1, typename T2, typename T3>
|
||||
type_of_size<4> function_arity_helper(R (*f)(T1, T2, T3));
|
||||
|
||||
template<typename R, typename T1, typename T2, typename T3, typename T4>
|
||||
type_of_size<5> function_arity_helper(R (*f)(T1, T2, T3, T4));
|
||||
|
||||
template<typename R, typename T1, typename T2, typename T3, typename T4,
|
||||
typename T5>
|
||||
type_of_size<6> function_arity_helper(R (*f)(T1, T2, T3, T4, T5));
|
||||
|
||||
template<typename R, typename T1, typename T2, typename T3, typename T4,
|
||||
typename T5, typename T6>
|
||||
type_of_size<7> function_arity_helper(R (*f)(T1, T2, T3, T4, T5, T6));
|
||||
|
||||
template<typename R, typename T1, typename T2, typename T3, typename T4,
|
||||
typename T5, typename T6, typename T7>
|
||||
type_of_size<8> function_arity_helper(R (*f)(T1, T2, T3, T4, T5, T6, T7));
|
||||
|
||||
template<typename R, typename T1, typename T2, typename T3, typename T4,
|
||||
typename T5, typename T6, typename T7, typename T8>
|
||||
type_of_size<9> function_arity_helper(R (*f)(T1, T2, T3, T4, T5, T6, T7, T8));
|
||||
|
||||
template<typename R, typename T1, typename T2, typename T3, typename T4,
|
||||
typename T5, typename T6, typename T7, typename T8, typename T9>
|
||||
type_of_size<10> function_arity_helper(R (*f)(T1, T2, T3, T4, T5, T6, T7, T8,
|
||||
T9));
|
||||
|
||||
template<typename R, typename T1, typename T2, typename T3, typename T4,
|
||||
typename T5, typename T6, typename T7, typename T8, typename T9,
|
||||
typename T10>
|
||||
type_of_size<11> function_arity_helper(R (*f)(T1, T2, T3, T4, T5, T6, T7, T8,
|
||||
T9, T10));
|
||||
} // end namespace detail
|
||||
|
||||
// Won't work with references
|
||||
template<typename Function>
|
||||
struct function_traits
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(int, arity = (sizeof(detail::function_arity_helper((Function*)0))-1));
|
||||
};
|
||||
|
||||
#endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||
} // boost
|
||||
|
||||
|
@ -839,7 +839,7 @@ properties. </p>
|
||||
<td valign="top" width="23%" bgcolor="#C0C0C0"><code>::boost::function_traits<F>::arity</code></td>
|
||||
<td valign="top" width="28%" bgcolor="#C0C0C0">Determine the arity of the function type <code>F</code>. </td>
|
||||
<td valign="top" width="13%" bgcolor="#C0C0C0"> </td>
|
||||
<td width="25%" bgcolor="#C0C0C0">P</td>
|
||||
<td width="25%" bgcolor="#C0C0C0">Without partial specialisation support, this template does not compile for reference types.</td>
|
||||
<td valign="top" width="5%"> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
@ -975,6 +975,13 @@ template.</p>
|
||||
<td valign="top" width="41%" bgcolor="#C0C0C0"><code><boost/type_traits/object_traits.hpp></code></td>
|
||||
<td valign="top" width="9%"> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td valign="top" bgcolor="#C0C0C0"><code>function_traits</code></td>
|
||||
<td valign="top" bgcolor="#C0C0C0"><code><boost/type_traits/function_traits.hpp></code></td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td valign="top" width="7%"> </td>
|
||||
<td valign="top" width="43%" bgcolor="#C0C0C0"><code>has_trivial_constructor</code></td>
|
||||
|
@ -45,11 +45,13 @@ struct is_double<double>
|
||||
|
||||
int test_main(int, char*[])
|
||||
{
|
||||
#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||
typedef int F2(float, double);
|
||||
|
||||
typedef boost::function_traits<F2> traits;
|
||||
|
||||
BOOST_TEST(traits::arity == 2);
|
||||
|
||||
#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||
BOOST_TEST(is_int<traits::result_type>::value);
|
||||
BOOST_TEST(is_float<traits::arg1_type>::value);
|
||||
BOOST_TEST(is_double<traits::arg2_type>::value);
|
||||
|
Reference in New Issue
Block a user