2
0
mirror of https://github.com/boostorg/python.git synced 2026-01-27 07:02:15 +00:00

Added is_reference_to_member_function_pointer

[SVN r16434]
This commit is contained in:
Dave Abrahams
2002-11-27 06:19:45 +00:00
parent 3fc70519cf
commit fb7c450b76
2 changed files with 77 additions and 5 deletions

View File

@@ -12,6 +12,7 @@
# include <boost/type_traits/is_class.hpp>
# include <boost/type_traits/is_const.hpp>
# include <boost/type_traits/is_volatile.hpp>
# include <boost/type_traits/is_member_function_pointer.hpp>
# include <boost/type_traits/remove_cv.hpp>
# include <boost/type_traits/remove_reference.hpp>
# include <boost/type_traits/remove_pointer.hpp>
@@ -69,6 +70,25 @@ struct is_pointer_to_function<T*> : is_function<T>
{
};
template <class T>
struct is_reference_to_member_function_pointer_impl : mpl::bool_c<false>
{
};
template <class T>
struct is_reference_to_member_function_pointer_impl<T&>
: is_member_function_pointer<typename remove_cv<T>::type>
{
};
template <class T>
struct is_reference_to_member_function_pointer
: is_reference_to_member_function_pointer_impl<T>
{
BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_reference_to_member_function_pointer,(T))
};
template <class T>
struct is_reference_to_function_pointer_aux
{
@@ -85,7 +105,11 @@ struct is_reference_to_function_pointer_aux
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
: mpl::if_c<
is_reference_to_function<T>::value
, mpl::bool_c<false>
, is_reference_to_function_pointer_aux<T>
>::type
{
};
@@ -372,18 +396,52 @@ struct is_reference_to_pointer
BOOST_STATIC_CONSTANT(
bool, value
= (is_reference<T>::value
&& sizeof(reference_to_pointer_helper(t)) == sizeof(inner_yes_type))
&& sizeof((reference_to_pointer_helper)(t)) == sizeof(inner_yes_type))
);
};
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
: mpl::if_<
is_reference<T>
, is_pointer_to_function_aux<T>
, mpl::bool_c<false>
>::type
{
BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_reference_to_function_pointer,(T))
};
template <class T>
struct is_member_function_pointer_help
: mpl::if_<is_member_function_pointer<T>, inner_yes_type, inner_no_type>
{};
template <typename V>
typename is_member_function_pointer_help<V>::type member_function_pointer_helper(V&);
outer_no_type member_function_pointer_helper(...);
template <class T>
struct is_pointer_to_member_function_aux
{
static T t;
BOOST_STATIC_CONSTANT(
bool, value
= sizeof((member_function_pointer_helper)(t)) == sizeof(inner_yes_type));
typedef mpl::bool_c<value> type;
};
template <class T>
struct is_reference_to_member_function_pointer
: mpl::if_<
is_reference<T>
, is_pointer_to_member_function_aux<T>
, mpl::bool_c<false>
>::type
{
BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_reference_to_member_function_pointer,(T))
};
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

@@ -9,22 +9,27 @@ struct X {};
int main()
{
using namespace boost::python::detail;
using namespace boost::python::detail;
typedef void (X::*pmf)();
assert(is_reference_to_function<int (&)()>::value);
assert(!is_reference_to_function<int (*)()>::value);
assert(!is_reference_to_function<int&>::value);
assert(!is_reference_to_function<pmf>::value);
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_pointer_to_function<pmf>::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_function_pointer<pmf>::value);
assert(is_reference_to_pointer<int*&>::value);
assert(is_reference_to_pointer<int* const&>::value);
@@ -34,6 +39,7 @@ using namespace boost::python::detail;
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<pmf>::value);
assert(!is_reference_to_pointer<int const volatile>::value);
assert(!is_reference_to_pointer<int>::value);
@@ -86,6 +92,14 @@ using namespace boost::python::detail;
assert(is_pointer_to_class<X const*>::value);
assert(is_pointer_to_class<X volatile*>::value);
assert(is_pointer_to_class<X const volatile*>::value);
assert(is_reference_to_member_function_pointer<pmf&>::value);
assert(is_reference_to_member_function_pointer<pmf const&>::value);
assert(is_reference_to_member_function_pointer<pmf volatile&>::value);
assert(is_reference_to_member_function_pointer<pmf const volatile&>::value);
assert(!is_reference_to_member_function_pointer<pmf[2]>::value);
assert(!is_reference_to_member_function_pointer<pmf(&)[2]>::value);
assert(!is_reference_to_member_function_pointer<pmf>::value);
return 0;
}