From 2d8a4b136aba8774769398b88fc9368eff5c6b7a Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Mon, 5 Aug 2002 02:33:26 +0000 Subject: [PATCH] Use function_traits in type_traits library [SVN r14675] --- include/boost/function.hpp | 508 +++++++++++++++++-------------------- 1 file changed, 233 insertions(+), 275 deletions(-) diff --git a/include/boost/function.hpp b/include/boost/function.hpp index 2cf9f0f..f4556fe 100644 --- a/include/boost/function.hpp +++ b/include/boost/function.hpp @@ -39,207 +39,6 @@ namespace boost { namespace detail { namespace function { -#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION - template - struct function_traits - { - typedef void result_type; - typedef void arg1_type; - typedef void arg2_type; - typedef void arg3_type; - typedef void arg4_type; - typedef void arg5_type; - typedef void arg6_type; - typedef void arg7_type; - typedef void arg8_type; - typedef void arg9_type; - typedef void arg10_type; - }; - - template - struct function_traits - { - typedef R result_type; - typedef unusable arg1_type; - typedef unusable arg2_type; - typedef unusable arg3_type; - typedef unusable arg4_type; - typedef unusable arg5_type; - typedef unusable arg6_type; - typedef unusable arg7_type; - typedef unusable arg8_type; - typedef unusable arg9_type; - typedef unusable arg10_type; - }; - - template - struct function_traits - { - typedef R result_type; - typedef T1 arg1_type; - typedef unusable arg2_type; - typedef unusable arg3_type; - typedef unusable arg4_type; - typedef unusable arg5_type; - typedef unusable arg6_type; - typedef unusable arg7_type; - typedef unusable arg8_type; - typedef unusable arg9_type; - typedef unusable arg10_type; - }; - - template - struct function_traits - { - typedef R result_type; - typedef T1 arg1_type; - typedef T2 arg2_type; - typedef unusable arg3_type; - typedef unusable arg4_type; - typedef unusable arg5_type; - typedef unusable arg6_type; - typedef unusable arg7_type; - typedef unusable arg8_type; - typedef unusable arg9_type; - typedef unusable arg10_type; - }; - - template - struct function_traits - { - typedef R result_type; - typedef T1 arg1_type; - typedef T2 arg2_type; - typedef T3 arg3_type; - typedef unusable arg4_type; - typedef unusable arg5_type; - typedef unusable arg6_type; - typedef unusable arg7_type; - typedef unusable arg8_type; - typedef unusable arg9_type; - typedef unusable arg10_type; - }; - - template - struct function_traits - { - typedef R result_type; - typedef T1 arg1_type; - typedef T2 arg2_type; - typedef T3 arg3_type; - typedef T4 arg4_type; - typedef unusable arg5_type; - typedef unusable arg6_type; - typedef unusable arg7_type; - typedef unusable arg8_type; - typedef unusable arg9_type; - typedef unusable arg10_type; - }; - - template - struct function_traits - { - 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 unusable arg6_type; - typedef unusable arg7_type; - typedef unusable arg8_type; - typedef unusable arg9_type; - typedef unusable arg10_type; - }; - - template - struct function_traits - { - 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 unusable arg7_type; - typedef unusable arg8_type; - typedef unusable arg9_type; - typedef unusable arg10_type; - }; - - template - struct function_traits - { - 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 unusable arg8_type; - typedef unusable arg9_type; - typedef unusable arg10_type; - }; - - template - struct function_traits - { - 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 unusable arg9_type; - typedef unusable arg10_type; - }; - - template - struct function_traits - { - 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 unusable arg10_type; - }; - - template - struct function_traits - { - 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; - }; -#endif - // Choose the appropriate underlying implementation template struct real_get_function_impl {}; @@ -530,6 +329,205 @@ namespace boost { BOOST_STATIC_CONSTANT(bool, value = !(is_same::value)); }; +#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION + template + struct get_arg1_type + { + typedef unusable type; + }; + + template + struct get_arg1_type + { + typedef typename Traits::arg1_type type; + }; + + template + struct get_arg2_type + { + typedef unusable type; + }; + + template + struct get_arg2_type + { + typedef typename Traits::arg2_type type; + }; + + template + struct get_arg3_type + { + typedef unusable type; + }; + + template + struct get_arg3_type + { + typedef typename Traits::arg3_type type; + }; + + template + struct get_arg4_type + { + typedef unusable type; + }; + + template + struct get_arg4_type + { + typedef typename Traits::arg4_type type; + }; + + template + struct get_arg5_type + { + typedef unusable type; + }; + + template + struct get_arg5_type + { + typedef typename Traits::arg5_type type; + }; + + template + struct get_arg6_type + { + typedef unusable type; + }; + + template + struct get_arg6_type + { + typedef typename Traits::arg6_type type; + }; + + template + struct get_arg7_type + { + typedef unusable type; + }; + + template + struct get_arg7_type + { + typedef typename Traits::arg7_type type; + }; + + template + struct get_arg8_type + { + typedef unusable type; + }; + + template + struct get_arg8_type + { + typedef typename Traits::arg8_type type; + }; + + template + struct get_arg9_type + { + typedef unusable type; + }; + + template + struct get_arg9_type + { + typedef typename Traits::arg9_type type; + }; + + template + struct get_arg10_type + { + typedef unusable type; + }; + + template + struct get_arg10_type + { + typedef typename Traits::arg10_type type; + }; + + template + struct maybe_decode_function_args + { + // Not a function, so just map the types directly + typedef InR R; + typedef InT1 T1; + typedef InT2 T2; + typedef InT3 T3; + typedef InT4 T4; + typedef InT5 T5; + typedef InT6 T6; + typedef InT7 T7; + typedef InT8 T8; + typedef InT9 T9; + typedef InT10 T10; + typedef InPolicy Policy; + typedef InMixin Mixin; + typedef InAllocator Allocator; + }; + + template + struct maybe_decode_function_args + { + typedef function_traits traits; + + typedef typename traits::result_type R; + typedef typename get_arg1_type<(traits::arity >= 1), traits>::type T1; + typedef typename get_arg2_type<(traits::arity >= 2), traits>::type T2; + typedef typename get_arg3_type<(traits::arity >= 3), traits>::type T3; + typedef typename get_arg4_type<(traits::arity >= 4), traits>::type T4; + typedef typename get_arg5_type<(traits::arity >= 5), traits>::type T5; + typedef typename get_arg6_type<(traits::arity >= 6), traits>::type T6; + typedef typename get_arg7_type<(traits::arity >= 7), traits>::type T7; + typedef typename get_arg8_type<(traits::arity >= 8), traits>::type T8; + typedef typename get_arg9_type<(traits::arity >= 9), traits>::type T9; + typedef typename get_arg10_type<(traits::arity >= 10), traits>::type T10; + typedef typename ct_if<(is_same::value), + empty_function_policy, + InT1>::type Policy; + typedef typename ct_if<(is_same::value), + empty_function_mixin, + InT2>::type Mixin; + typedef typename ct_if<(is_same::value), + std::allocator, + InT3>::type Allocator; + }; + +#endif // ndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION + template< typename InR, typename InT1, @@ -549,82 +547,42 @@ namespace boost { class get_function_impl { #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION - typedef function_traits::type> traits; - public: - - typedef typename ct_if<(is_function::value), - typename traits::result_type, - InR>::type R; - typedef typename ct_if<(is_function::value), - typename traits::arg1_type, - InT1>::type T1; - typedef typename ct_if<(is_function::value), - typename traits::arg2_type, - InT2>::type T2; - typedef typename ct_if<(is_function::value), - typename traits::arg3_type, - InT3>::type T3; - typedef typename ct_if<(is_function::value), - typename traits::arg4_type, - InT4>::type T4; - typedef typename ct_if<(is_function::value), - typename traits::arg5_type, - InT5>::type T5; - typedef typename ct_if<(is_function::value), - typename traits::arg6_type, - InT6>::type T6; - typedef typename ct_if<(is_function::value), - typename traits::arg7_type, - InT7>::type T7; - typedef typename ct_if<(is_function::value), - typename traits::arg8_type, - InT8>::type T8; - typedef typename ct_if<(is_function::value), - typename traits::arg9_type, - InT9>::type T9; - typedef typename ct_if<(is_function::value), - typename traits::arg10_type, - InT10>::type T10; - typedef typename ct_if< - (type_traits::ice_and< - (is_function::value), - (is_not_same::value) - >::value), - InT1, - InPolicy>::type Policy; - - typedef typename ct_if< - (type_traits::ice_and< - (is_function::value), - (is_not_same::value) - >::value), - InT2, - InMixin>::type Mixin; - - typedef typename ct_if< - (type_traits::ice_and< - (is_function::value), - (is_not_same::value) - >::value), - InT3, - InAllocator>::type Allocator; + typedef maybe_decode_function_args<(is_function::value), + InR, InT1, InT2, InT3, InT4, InT5, + InT6, InT7, InT8, InT9, InT10, + InPolicy, InMixin, InAllocator> + decoder; + typedef typename decoder::R R; + typedef typename decoder::T1 T1; + typedef typename decoder::T2 T2; + typedef typename decoder::T3 T3; + typedef typename decoder::T4 T4; + typedef typename decoder::T5 T5; + typedef typename decoder::T6 T6; + typedef typename decoder::T7 T7; + typedef typename decoder::T8 T8; + typedef typename decoder::T9 T9; + typedef typename decoder::T10 T10; + typedef typename decoder::Policy Policy; + typedef typename decoder::Mixin Mixin; + typedef typename decoder::Allocator Allocator; #else + typedef InR R; + typedef InT1 T1; + typedef InT2 T2; + typedef InT3 T3; + typedef InT4 T4; + typedef InT5 T5; + typedef InT6 T6; + typedef InT7 T7; + typedef InT8 T8; + typedef InT9 T9; + typedef InT10 T10; + typedef InPolicy Policy; + typedef InMixin Mixin; + typedef InAllocator Allocator; +#endif // def BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION public: - typedef InR R; - typedef InT1 T1; - typedef InT2 T2; - typedef InT3 T3; - typedef InT4 T4; - typedef InT5 T5; - typedef InT6 T6; - typedef InT7 T7; - typedef InT8 T8; - typedef InT9 T9; - typedef InT10 T10; - typedef InPolicy Policy; - typedef InMixin Mixin; - typedef InAllocator Allocator; -#endif typedef typename real_get_function_impl< (count_used_args::value) >::template params