Skip to content

Commit fb7c450

Browse files
committed
Added is_reference_to_member_function_pointer
[SVN r16434]
1 parent 3fc7051 commit fb7c450

2 files changed

Lines changed: 77 additions & 5 deletions

File tree

include/boost/python/detail/indirect_traits.hpp

Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# include <boost/type_traits/is_class.hpp>
1313
# include <boost/type_traits/is_const.hpp>
1414
# include <boost/type_traits/is_volatile.hpp>
15+
# include <boost/type_traits/is_member_function_pointer.hpp>
1516
# include <boost/type_traits/remove_cv.hpp>
1617
# include <boost/type_traits/remove_reference.hpp>
1718
# include <boost/type_traits/remove_pointer.hpp>
@@ -69,6 +70,25 @@ struct is_pointer_to_function<T*> : is_function<T>
6970
{
7071
};
7172

73+
template <class T>
74+
struct is_reference_to_member_function_pointer_impl : mpl::bool_c<false>
75+
{
76+
};
77+
78+
template <class T>
79+
struct is_reference_to_member_function_pointer_impl<T&>
80+
: is_member_function_pointer<typename remove_cv<T>::type>
81+
{
82+
};
83+
84+
85+
template <class T>
86+
struct is_reference_to_member_function_pointer
87+
: is_reference_to_member_function_pointer_impl<T>
88+
{
89+
BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_reference_to_member_function_pointer,(T))
90+
};
91+
7292
template <class T>
7393
struct is_reference_to_function_pointer_aux
7494
{
@@ -85,7 +105,11 @@ struct is_reference_to_function_pointer_aux
85105

86106
template <class T>
87107
struct is_reference_to_function_pointer
88-
: mpl::if_c<is_reference_to_function<T>::value, mpl::bool_c<false>, is_reference_to_function_pointer_aux<T> >::type
108+
: mpl::if_c<
109+
is_reference_to_function<T>::value
110+
, mpl::bool_c<false>
111+
, is_reference_to_function_pointer_aux<T>
112+
>::type
89113
{
90114
};
91115

@@ -372,18 +396,52 @@ struct is_reference_to_pointer
372396
BOOST_STATIC_CONSTANT(
373397
bool, value
374398
= (is_reference<T>::value
375-
&& sizeof(reference_to_pointer_helper(t)) == sizeof(inner_yes_type))
399+
&& sizeof((reference_to_pointer_helper)(t)) == sizeof(inner_yes_type))
376400
);
377401
};
378402

379403
template <class T>
380404
struct is_reference_to_function_pointer
381-
: mpl::if_<is_reference<T>
382-
, is_pointer_to_function_aux<T>, mpl::bool_c<false> >::type
405+
: mpl::if_<
406+
is_reference<T>
407+
, is_pointer_to_function_aux<T>
408+
, mpl::bool_c<false>
409+
>::type
383410
{
384411
BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_reference_to_function_pointer,(T))
385412
};
386413

414+
415+
template <class T>
416+
struct is_member_function_pointer_help
417+
: mpl::if_<is_member_function_pointer<T>, inner_yes_type, inner_no_type>
418+
{};
419+
420+
template <typename V>
421+
typename is_member_function_pointer_help<V>::type member_function_pointer_helper(V&);
422+
outer_no_type member_function_pointer_helper(...);
423+
424+
template <class T>
425+
struct is_pointer_to_member_function_aux
426+
{
427+
static T t;
428+
BOOST_STATIC_CONSTANT(
429+
bool, value
430+
= sizeof((member_function_pointer_helper)(t)) == sizeof(inner_yes_type));
431+
typedef mpl::bool_c<value> type;
432+
};
433+
434+
template <class T>
435+
struct is_reference_to_member_function_pointer
436+
: mpl::if_<
437+
is_reference<T>
438+
, is_pointer_to_member_function_aux<T>
439+
, mpl::bool_c<false>
440+
>::type
441+
{
442+
BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_reference_to_member_function_pointer,(T))
443+
};
444+
387445
template <typename V>
388446
typename is_class_help<V>::type reference_to_class_helper(V const volatile&);
389447
outer_no_type reference_to_class_helper(...);

test/indirect_traits_test.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,27 @@ struct X {};
99

1010
int main()
1111
{
12-
using namespace boost::python::detail;
12+
using namespace boost::python::detail;
13+
14+
typedef void (X::*pmf)();
1315

1416
assert(is_reference_to_function<int (&)()>::value);
1517
assert(!is_reference_to_function<int (*)()>::value);
1618
assert(!is_reference_to_function<int&>::value);
19+
assert(!is_reference_to_function<pmf>::value);
1720

1821
assert(!is_pointer_to_function<int (&)()>::value);
1922
assert(is_pointer_to_function<int (*)()>::value);
2023
assert(!is_pointer_to_function<int (*&)()>::value);
2124
assert(!is_pointer_to_function<int (*const&)()>::value);
25+
assert(!is_pointer_to_function<pmf>::value);
2226

2327
assert(!is_reference_to_function_pointer<int (&)()>::value);
2428
assert(!is_reference_to_function_pointer<int (*)()>::value);
2529
assert(!is_reference_to_function_pointer<int&>::value);
2630
assert(is_reference_to_function_pointer<int (*&)()>::value);
2731
assert(is_reference_to_function_pointer<int (*const&)()>::value);
32+
assert(!is_reference_to_function_pointer<pmf>::value);
2833

2934
assert(is_reference_to_pointer<int*&>::value);
3035
assert(is_reference_to_pointer<int* const&>::value);
@@ -34,6 +39,7 @@ using namespace boost::python::detail;
3439
assert(is_reference_to_pointer<int const* const&>::value);
3540
assert(is_reference_to_pointer<int const*volatile&>::value);
3641
assert(is_reference_to_pointer<int const*const volatile&>::value);
42+
assert(!is_reference_to_pointer<pmf>::value);
3743

3844
assert(!is_reference_to_pointer<int const volatile>::value);
3945
assert(!is_reference_to_pointer<int>::value);
@@ -86,6 +92,14 @@ using namespace boost::python::detail;
8692
assert(is_pointer_to_class<X const*>::value);
8793
assert(is_pointer_to_class<X volatile*>::value);
8894
assert(is_pointer_to_class<X const volatile*>::value);
95+
96+
assert(is_reference_to_member_function_pointer<pmf&>::value);
97+
assert(is_reference_to_member_function_pointer<pmf const&>::value);
98+
assert(is_reference_to_member_function_pointer<pmf volatile&>::value);
99+
assert(is_reference_to_member_function_pointer<pmf const volatile&>::value);
100+
assert(!is_reference_to_member_function_pointer<pmf[2]>::value);
101+
assert(!is_reference_to_member_function_pointer<pmf(&)[2]>::value);
102+
assert(!is_reference_to_member_function_pointer<pmf>::value);
89103

90104
return 0;
91105
}

0 commit comments

Comments
 (0)