1010
1111# include < boost/python/object_core.hpp>
1212# include < boost/python/call.hpp>
13+ # include < boost/iterator/detail/enable_if.hpp>
14+ # include < boost/mpl/bool.hpp>
15+
16+ # include < boost/iterator/detail/config_def.hpp>
1317
1418namespace boost { namespace python { namespace api {
1519
20+ # if !defined(BOOST_NO_SFINAE) && !defined(BOOST_NO_IS_CONVERTIBLE)
21+
22+ template <class X > char
23+ is_object_operators_helper (object_operators<X> const &);
24+
25+ typedef char (&no_type)[2];
26+ no_type is_object_operators_helper (...);
27+
28+ template <class X > X& make ();
29+
30+ template <class L , class R >
31+ struct is_object_operators
32+ {
33+ enum {
34+ value
35+ = (sizeof (api::is_object_operators_helper (api::make<L>()))
36+ + sizeof (api::is_object_operators_helper (api::make<R>()))
37+ < 4
38+ )
39+ };
40+ typedef mpl::bool_<value> type;
41+ };
42+
43+ template <class L , class R , class T >
44+ struct enable_binary
45+ : boost::iterators::enable_if<is_object_operators<L,R>, T>
46+ {};
47+ # define BOOST_PYTHON_BINARY_RETURN (T ) typename enable_binary<L,R,T>::type
48+ # else
49+ # define BOOST_PYTHON_BINARY_RETURN (T ) T
50+ # endif
51+
1652template <class U >
1753object object_operators<U>::operator ()() const
1854{
@@ -37,12 +73,12 @@ object_operators<U>::operator!() const
3773 return !PyObject_IsTrue (x.ptr ());
3874}
3975
40- # define BOOST_PYTHON_COMPARE_OP (op, opid ) \
41- template <class L , class R > \
42- bool operator op (L const & l, R const & r) \
43- { \
44- return PyObject_RichCompareBool ( \
45- object (l).ptr (), object (r).ptr (), opid); \
76+ # define BOOST_PYTHON_COMPARE_OP (op, opid ) \
77+ template <class L , class R > \
78+ BOOST_PYTHON_BINARY_RETURN ( bool ) operator op (L const & l, R const & r) \
79+ { \
80+ return PyObject_RichCompareBool ( \
81+ object (l).ptr (), object (r).ptr (), opid); \
4682}
4783BOOST_PYTHON_COMPARE_OP (>, Py_GT)
4884BOOST_PYTHON_COMPARE_OP (>=, Py_GE)
@@ -55,7 +91,7 @@ BOOST_PYTHON_COMPARE_OP(!=, Py_NE)
5591# define BOOST_PYTHON_BINARY_OPERATOR (op ) \
5692BOOST_PYTHON_DECL object operator op (object const & l, object const & r); \
5793template <class L , class R > \
58- object operator op (L const & l, R const & r) \
94+ BOOST_PYTHON_BINARY_RETURN ( object) operator op (L const & l, R const & r) \
5995{ \
6096 return object (l) op object (r); \
6197}
@@ -93,4 +129,6 @@ BOOST_PYTHON_INPLACE_OPERATOR(|=)
93129
94130}}} // namespace boost::python
95131
132+ #include < boost/iterator/detail/config_undef.hpp>
133+
96134#endif // OBJECT_OPERATORS_DWA2002617_HPP
0 commit comments