2
0
mirror of https://github.com/boostorg/python.git synced 2026-01-24 06:02:14 +00:00

is_reference_to_function_pointer implementation

[SVN r16278]
This commit is contained in:
Dave Abrahams
2002-11-16 06:55:04 +00:00
parent 06fe0f1bcc
commit f2ac0145da
3 changed files with 76 additions and 15 deletions

View File

@@ -12,6 +12,7 @@
# include <boost/python/detail/indirect_traits.hpp>
# include <boost/mpl/logical/not.hpp>
# include <boost/mpl/logical/and.hpp>
# include <boost/mpl/logical/or.hpp>
# include <boost/type_traits/add_reference.hpp>
# include <boost/mpl/lambda.hpp>
# include <boost/mpl/apply.hpp>
@@ -101,29 +102,37 @@ namespace detail
: tuple_extract<
Tuple,
mpl::logical_and<
is_reference_to_class<add_reference<mpl::_> >
mpl::logical_not<is_same<not_specified const&,mpl::_1> >
, is_reference_to_class<add_reference<mpl::_> >
, mpl::logical_not<is_reference_to_keywords<add_reference<mpl::_1> > >
>
>
{
};
template <class Tuple>
struct default_implementation_extract
: tuple_extract<
Tuple,
mpl::logical_or<
is_reference_to_function_pointer<mpl::_1>
, is_reference_to_function<mpl::_1>
, is_same<mpl::_1,tuples::null_type>
>
>
{
};
# define BOOST_PYTHON_DEF_HELPER_TAIL default_call_policies, keywords<0>, char const*
template <class T1, class T2 = not_specified, class T3 = not_specified>
struct def_helper
{
typedef typename mpl::if_<
is_same<T2, not_specified>
, boost::tuples::tuple<T1 const&, BOOST_PYTHON_DEF_HELPER_TAIL>
, typename mpl::if_<
is_same<T3, not_specified>
, boost::tuples::tuple<T1 const&, T2 const&, BOOST_PYTHON_DEF_HELPER_TAIL>
, boost::tuples::tuple<T1 const&, T2 const&, T3 const&>
>::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<all_t>::extract(m_all);
}
typedef
typename default_implementation_extract<all_t>::result_type default_implementation() const
{
return policy_extract<all_t>::extract(m_all);
}
all_t m_all;
not_specified m_nil;
};
# undef BOOST_PYTHON_DEF_HELPER_TAIL
}

View File

@@ -58,6 +58,7 @@ struct is_reference_to_function<T&>
BOOST_STATIC_CONSTANT(bool, value = is_function<T>::value);
};
# if 0
template <class T>
struct is_reference_to_function<T const&>
{
@@ -75,7 +76,7 @@ struct is_reference_to_function<T const volatile&>
{
BOOST_STATIC_CONSTANT(bool, value = is_function<T>::value);
};
# endif
template <class T>
struct is_pointer_to_function
{
@@ -89,6 +90,25 @@ struct is_pointer_to_function<T*>
BOOST_STATIC_CONSTANT(bool, value = is_function<T>::value);
};
template <class T>
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<T>::value
& is_pointer_to_function<
typename remove_cv<
typename remove_reference<T>::type
>::type
>::value));
};
template <class T>
struct is_reference_to_function_pointer
: mpl::if_c<is_reference_to_function<T>::value, mpl::bool_c<false>, is_reference_to_function_pointer_aux<T> >::type
{
};
template <class T>
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 <class T>
@@ -248,7 +268,7 @@ struct is_reference_to_function
};
template <class T>
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 <class T>
struct is_pointer_to_function
: mpl::if_<is_pointer<T>, is_pointer_to_function_aux<T>, mpl::bool_c<false> >::type
{
};
struct false_helper1
{
template <class T>
@@ -368,6 +394,13 @@ struct is_reference_to_pointer
);
};
template <class T>
struct is_reference_to_function_pointer
: mpl::if_<is_reference<T>
, is_pointer_to_function_aux<T>, mpl::bool_c<false> >::type
{
};
template <typename V>
typename is_class_help<V>::type reference_to_class_helper(V const volatile&);
outer_no_type reference_to_class_helper(...);

View File

@@ -17,11 +17,23 @@ using namespace boost::python::detail;
assert(!is_pointer_to_function<int (&)()>::value);
assert(is_pointer_to_function<int (*)()>::value);
assert(!is_pointer_to_function<int (*&)()>::value);
assert(!is_pointer_to_function<int (*const&)()>::value);
assert(!is_reference_to_function_pointer<int (&)()>::value);
assert(!is_reference_to_function_pointer<int (*)()>::value);
assert(!is_reference_to_function_pointer<int&>::value);
assert(is_reference_to_function_pointer<int (*&)()>::value);
assert(is_reference_to_function_pointer<int (*const&)()>::value);
assert(is_reference_to_pointer<int*&>::value);
assert(is_reference_to_pointer<int* const&>::value);
assert(is_reference_to_pointer<int*volatile&>::value);
assert(is_reference_to_pointer<int*const volatile&>::value);
assert(is_reference_to_pointer<int const*&>::value);
assert(is_reference_to_pointer<int const* const&>::value);
assert(is_reference_to_pointer<int const*volatile&>::value);
assert(is_reference_to_pointer<int const*const volatile&>::value);
assert(!is_reference_to_pointer<int const volatile>::value);
assert(!is_reference_to_pointer<int>::value);