From f2ac0145daa763f17994806dd64b966e2ef7e95b Mon Sep 17 00:00:00 2001 From: Dave Abrahams Date: Sat, 16 Nov 2002 06:55:04 +0000 Subject: [PATCH] is_reference_to_function_pointer implementation [SVN r16278] --- include/boost/python/detail/def_helper.hpp | 40 +++++++++++++------ .../boost/python/detail/indirect_traits.hpp | 39 ++++++++++++++++-- test/indirect_traits_test.cpp | 12 ++++++ 3 files changed, 76 insertions(+), 15 deletions(-) diff --git a/include/boost/python/detail/def_helper.hpp b/include/boost/python/detail/def_helper.hpp index 4135af55..4c70fd8f 100644 --- a/include/boost/python/detail/def_helper.hpp +++ b/include/boost/python/detail/def_helper.hpp @@ -12,6 +12,7 @@ # include # include # include +# include # include # include # include @@ -101,29 +102,37 @@ namespace detail : tuple_extract< Tuple, mpl::logical_and< - is_reference_to_class > + mpl::logical_not > + , is_reference_to_class > , mpl::logical_not > > > > { }; + template + struct default_implementation_extract + : tuple_extract< + Tuple, + mpl::logical_or< + is_reference_to_function_pointer + , is_reference_to_function + , is_same + > + > + { + }; + # define BOOST_PYTHON_DEF_HELPER_TAIL default_call_policies, keywords<0>, char const* template struct def_helper { - typedef typename mpl::if_< - is_same - , boost::tuples::tuple - , typename mpl::if_< - is_same - , boost::tuples::tuple - , boost::tuples::tuple - >::type - >::type all_t; + typedef boost::tuples::tuple< + T1 const&, T2 const&, T3 const&, default_call_policies, keywords<0>, char const* + > all_t; - def_helper(T1 const& a1) : m_all(a1) {} - def_helper(T1 const& a1, T2 const& a2) : m_all(a1,a2) {} + def_helper(T1 const& a1) : m_all(a1,m_nil,m_nil) {} + def_helper(T1 const& a1, T2 const& a2) : m_all(a1,a2,m_nil) {} def_helper(T1 const& a1, T2 const& a2, T3 const& a3) : m_all(a1,a2,a3) {} char const* doc() const @@ -140,8 +149,15 @@ namespace detail { return policy_extract::extract(m_all); } + + typedef + typename default_implementation_extract::result_type default_implementation() const + { + return policy_extract::extract(m_all); + } all_t m_all; + not_specified m_nil; }; # undef BOOST_PYTHON_DEF_HELPER_TAIL } diff --git a/include/boost/python/detail/indirect_traits.hpp b/include/boost/python/detail/indirect_traits.hpp index 5bcc4191..23d14a64 100644 --- a/include/boost/python/detail/indirect_traits.hpp +++ b/include/boost/python/detail/indirect_traits.hpp @@ -58,6 +58,7 @@ struct is_reference_to_function BOOST_STATIC_CONSTANT(bool, value = is_function::value); }; +# if 0 template struct is_reference_to_function { @@ -75,7 +76,7 @@ struct is_reference_to_function { BOOST_STATIC_CONSTANT(bool, value = is_function::value); }; - +# endif template struct is_pointer_to_function { @@ -89,6 +90,25 @@ struct is_pointer_to_function BOOST_STATIC_CONSTANT(bool, value = is_function::value); }; +template +struct is_reference_to_function_pointer_aux +{ + // There's no such thing as a pointer-to-cv-function, so we don't need specializations for those + BOOST_STATIC_CONSTANT(bool, value = ( + is_reference::value + & is_pointer_to_function< + typename remove_cv< + typename remove_reference::type + >::type + >::value)); +}; + +template +struct is_reference_to_function_pointer + : mpl::if_c::value, mpl::bool_c, is_reference_to_function_pointer_aux >::type +{ +}; + template struct is_reference_to_non_const { @@ -238,7 +258,7 @@ struct is_reference_to_function_aux { static T t; BOOST_STATIC_CONSTANT( - bool, value = sizeof(is_function_ref_tester(t,0)) == sizeof(::boost::type_traits::yes_type)); + bool, value = sizeof(detail::is_function_ref_tester(t,0)) == sizeof(::boost::type_traits::yes_type)); }; template @@ -248,7 +268,7 @@ struct is_reference_to_function }; template -struct is_pointer_to_function +struct is_pointer_to_function_aux { static T t; BOOST_STATIC_CONSTANT( @@ -256,6 +276,12 @@ struct is_pointer_to_function = sizeof(::boost::type_traits::is_function_ptr_tester(t)) == sizeof(::boost::type_traits::yes_type)); }; +template +struct is_pointer_to_function + : mpl::if_, is_pointer_to_function_aux, mpl::bool_c >::type +{ +}; + struct false_helper1 { template @@ -368,6 +394,13 @@ struct is_reference_to_pointer ); }; +template +struct is_reference_to_function_pointer + : mpl::if_ + , is_pointer_to_function_aux, mpl::bool_c >::type +{ +}; + template typename is_class_help::type reference_to_class_helper(V const volatile&); outer_no_type reference_to_class_helper(...); diff --git a/test/indirect_traits_test.cpp b/test/indirect_traits_test.cpp index 1f52afcd..561a946a 100644 --- a/test/indirect_traits_test.cpp +++ b/test/indirect_traits_test.cpp @@ -17,11 +17,23 @@ using namespace boost::python::detail; assert(!is_pointer_to_function::value); assert(is_pointer_to_function::value); + assert(!is_pointer_to_function::value); + assert(!is_pointer_to_function::value); + assert(!is_reference_to_function_pointer::value); + assert(!is_reference_to_function_pointer::value); + assert(!is_reference_to_function_pointer::value); + assert(is_reference_to_function_pointer::value); + assert(is_reference_to_function_pointer::value); + assert(is_reference_to_pointer::value); assert(is_reference_to_pointer::value); assert(is_reference_to_pointer::value); assert(is_reference_to_pointer::value); + assert(is_reference_to_pointer::value); + assert(is_reference_to_pointer::value); + assert(is_reference_to_pointer::value); + assert(is_reference_to_pointer::value); assert(!is_reference_to_pointer::value); assert(!is_reference_to_pointer::value);