Skip to content

Commit f2ac014

Browse files
committed
is_reference_to_function_pointer implementation
[SVN r16278]
1 parent 06fe0f1 commit f2ac014

File tree

3 files changed

+76
-15
lines changed

3 files changed

+76
-15
lines changed

include/boost/python/detail/def_helper.hpp

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# include <boost/python/detail/indirect_traits.hpp>
1313
# include <boost/mpl/logical/not.hpp>
1414
# include <boost/mpl/logical/and.hpp>
15+
# include <boost/mpl/logical/or.hpp>
1516
# include <boost/type_traits/add_reference.hpp>
1617
# include <boost/mpl/lambda.hpp>
1718
# include <boost/mpl/apply.hpp>
@@ -101,29 +102,37 @@ namespace detail
101102
: tuple_extract<
102103
Tuple,
103104
mpl::logical_and<
104-
is_reference_to_class<add_reference<mpl::_> >
105+
mpl::logical_not<is_same<not_specified const&,mpl::_1> >
106+
, is_reference_to_class<add_reference<mpl::_> >
105107
, mpl::logical_not<is_reference_to_keywords<add_reference<mpl::_1> > >
106108
>
107109
>
108110
{
109111
};
110112

113+
template <class Tuple>
114+
struct default_implementation_extract
115+
: tuple_extract<
116+
Tuple,
117+
mpl::logical_or<
118+
is_reference_to_function_pointer<mpl::_1>
119+
, is_reference_to_function<mpl::_1>
120+
, is_same<mpl::_1,tuples::null_type>
121+
>
122+
>
123+
{
124+
};
125+
111126
# define BOOST_PYTHON_DEF_HELPER_TAIL default_call_policies, keywords<0>, char const*
112127
template <class T1, class T2 = not_specified, class T3 = not_specified>
113128
struct def_helper
114129
{
115-
typedef typename mpl::if_<
116-
is_same<T2, not_specified>
117-
, boost::tuples::tuple<T1 const&, BOOST_PYTHON_DEF_HELPER_TAIL>
118-
, typename mpl::if_<
119-
is_same<T3, not_specified>
120-
, boost::tuples::tuple<T1 const&, T2 const&, BOOST_PYTHON_DEF_HELPER_TAIL>
121-
, boost::tuples::tuple<T1 const&, T2 const&, T3 const&>
122-
>::type
123-
>::type all_t;
130+
typedef boost::tuples::tuple<
131+
T1 const&, T2 const&, T3 const&, default_call_policies, keywords<0>, char const*
132+
> all_t;
124133

125-
def_helper(T1 const& a1) : m_all(a1) {}
126-
def_helper(T1 const& a1, T2 const& a2) : m_all(a1,a2) {}
134+
def_helper(T1 const& a1) : m_all(a1,m_nil,m_nil) {}
135+
def_helper(T1 const& a1, T2 const& a2) : m_all(a1,a2,m_nil) {}
127136
def_helper(T1 const& a1, T2 const& a2, T3 const& a3) : m_all(a1,a2,a3) {}
128137

129138
char const* doc() const
@@ -140,8 +149,15 @@ namespace detail
140149
{
141150
return policy_extract<all_t>::extract(m_all);
142151
}
152+
153+
typedef
154+
typename default_implementation_extract<all_t>::result_type default_implementation() const
155+
{
156+
return policy_extract<all_t>::extract(m_all);
157+
}
143158

144159
all_t m_all;
160+
not_specified m_nil;
145161
};
146162
# undef BOOST_PYTHON_DEF_HELPER_TAIL
147163
}

include/boost/python/detail/indirect_traits.hpp

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ struct is_reference_to_function<T&>
5858
BOOST_STATIC_CONSTANT(bool, value = is_function<T>::value);
5959
};
6060

61+
# if 0
6162
template <class T>
6263
struct is_reference_to_function<T const&>
6364
{
@@ -75,7 +76,7 @@ struct is_reference_to_function<T const volatile&>
7576
{
7677
BOOST_STATIC_CONSTANT(bool, value = is_function<T>::value);
7778
};
78-
79+
# endif
7980
template <class T>
8081
struct is_pointer_to_function
8182
{
@@ -89,6 +90,25 @@ struct is_pointer_to_function<T*>
8990
BOOST_STATIC_CONSTANT(bool, value = is_function<T>::value);
9091
};
9192

93+
template <class T>
94+
struct is_reference_to_function_pointer_aux
95+
{
96+
// There's no such thing as a pointer-to-cv-function, so we don't need specializations for those
97+
BOOST_STATIC_CONSTANT(bool, value = (
98+
is_reference<T>::value
99+
& is_pointer_to_function<
100+
typename remove_cv<
101+
typename remove_reference<T>::type
102+
>::type
103+
>::value));
104+
};
105+
106+
template <class T>
107+
struct is_reference_to_function_pointer
108+
: mpl::if_c<is_reference_to_function<T>::value, mpl::bool_c<false>, is_reference_to_function_pointer_aux<T> >::type
109+
{
110+
};
111+
92112
template <class T>
93113
struct is_reference_to_non_const
94114
{
@@ -238,7 +258,7 @@ struct is_reference_to_function_aux
238258
{
239259
static T t;
240260
BOOST_STATIC_CONSTANT(
241-
bool, value = sizeof(is_function_ref_tester(t,0)) == sizeof(::boost::type_traits::yes_type));
261+
bool, value = sizeof(detail::is_function_ref_tester(t,0)) == sizeof(::boost::type_traits::yes_type));
242262
};
243263

244264
template <class T>
@@ -248,14 +268,20 @@ struct is_reference_to_function
248268
};
249269

250270
template <class T>
251-
struct is_pointer_to_function
271+
struct is_pointer_to_function_aux
252272
{
253273
static T t;
254274
BOOST_STATIC_CONSTANT(
255275
bool, value
256276
= sizeof(::boost::type_traits::is_function_ptr_tester(t)) == sizeof(::boost::type_traits::yes_type));
257277
};
258278

279+
template <class T>
280+
struct is_pointer_to_function
281+
: mpl::if_<is_pointer<T>, is_pointer_to_function_aux<T>, mpl::bool_c<false> >::type
282+
{
283+
};
284+
259285
struct false_helper1
260286
{
261287
template <class T>
@@ -368,6 +394,13 @@ struct is_reference_to_pointer
368394
);
369395
};
370396

397+
template <class T>
398+
struct is_reference_to_function_pointer
399+
: mpl::if_<is_reference<T>
400+
, is_pointer_to_function_aux<T>, mpl::bool_c<false> >::type
401+
{
402+
};
403+
371404
template <typename V>
372405
typename is_class_help<V>::type reference_to_class_helper(V const volatile&);
373406
outer_no_type reference_to_class_helper(...);

test/indirect_traits_test.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,23 @@ using namespace boost::python::detail;
1717

1818
assert(!is_pointer_to_function<int (&)()>::value);
1919
assert(is_pointer_to_function<int (*)()>::value);
20+
assert(!is_pointer_to_function<int (*&)()>::value);
21+
assert(!is_pointer_to_function<int (*const&)()>::value);
2022

23+
assert(!is_reference_to_function_pointer<int (&)()>::value);
24+
assert(!is_reference_to_function_pointer<int (*)()>::value);
25+
assert(!is_reference_to_function_pointer<int&>::value);
26+
assert(is_reference_to_function_pointer<int (*&)()>::value);
27+
assert(is_reference_to_function_pointer<int (*const&)()>::value);
28+
2129
assert(is_reference_to_pointer<int*&>::value);
2230
assert(is_reference_to_pointer<int* const&>::value);
2331
assert(is_reference_to_pointer<int*volatile&>::value);
2432
assert(is_reference_to_pointer<int*const volatile&>::value);
33+
assert(is_reference_to_pointer<int const*&>::value);
34+
assert(is_reference_to_pointer<int const* const&>::value);
35+
assert(is_reference_to_pointer<int const*volatile&>::value);
36+
assert(is_reference_to_pointer<int const*const volatile&>::value);
2537

2638
assert(!is_reference_to_pointer<int const volatile>::value);
2739
assert(!is_reference_to_pointer<int>::value);

0 commit comments

Comments
 (0)