mirror of
https://github.com/boostorg/python.git
synced 2026-01-22 05:22:45 +00:00
Make object comparison operators return object instead of bool, to
accomodate strange beasts like numarray arrays that return arrays that can't be used as truth values from their comparison ops. Fix numpy test for portability with old doctest (again!) [SVN r35572]
This commit is contained in:
@@ -854,12 +854,12 @@ void del(proxy<T> const& x);
|
||||
</dl>
|
||||
<pre>
|
||||
<a name="comparisons-spec"></a>
|
||||
template<class L,class R> bool operator>(L const&l,R const&r);
|
||||
template<class L,class R> bool operator>=(L const&l,R const&r);
|
||||
template<class L,class R> bool operator<(L const&l,R const&r);
|
||||
template<class L,class R> bool operator<=(L const&l,R const&r);
|
||||
template<class L,class R> bool operator==(L const&l,R const&r);
|
||||
template<class L,class R> bool operator!=(L const&l,R const&r);
|
||||
template<class L,class R> object operator>(L const&l,R const&r);
|
||||
template<class L,class R> object operator>=(L const&l,R const&r);
|
||||
template<class L,class R> object operator<(L const&l,R const&r);
|
||||
template<class L,class R> object operator<=(L const&l,R const&r);
|
||||
template<class L,class R> object operator==(L const&l,R const&r);
|
||||
template<class L,class R> object operator!=(L const&l,R const&r);
|
||||
</pre>
|
||||
|
||||
<dl class="function-semantics">
|
||||
|
||||
@@ -73,17 +73,11 @@ object_operators<U>::operator!() const
|
||||
|
||||
# define BOOST_PYTHON_COMPARE_OP(op, opid) \
|
||||
template <class L, class R> \
|
||||
BOOST_PYTHON_BINARY_RETURN(bool) operator op(L const& l, R const& r) \
|
||||
BOOST_PYTHON_BINARY_RETURN(object) operator op(L const& l, R const& r) \
|
||||
{ \
|
||||
return PyObject_RichCompareBool( \
|
||||
return PyObject_RichCompare( \
|
||||
object(l).ptr(), object(r).ptr(), opid); \
|
||||
}
|
||||
BOOST_PYTHON_COMPARE_OP(>, Py_GT)
|
||||
BOOST_PYTHON_COMPARE_OP(>=, Py_GE)
|
||||
BOOST_PYTHON_COMPARE_OP(<, Py_LT)
|
||||
BOOST_PYTHON_COMPARE_OP(<=, Py_LE)
|
||||
BOOST_PYTHON_COMPARE_OP(==, Py_EQ)
|
||||
BOOST_PYTHON_COMPARE_OP(!=, Py_NE)
|
||||
# undef BOOST_PYTHON_COMPARE_OP
|
||||
|
||||
# define BOOST_PYTHON_BINARY_OPERATOR(op) \
|
||||
@@ -93,6 +87,12 @@ BOOST_PYTHON_BINARY_RETURN(object) operator op(L const& l, R const& r) \
|
||||
{ \
|
||||
return object(l) op object(r); \
|
||||
}
|
||||
BOOST_PYTHON_BINARY_OPERATOR(>)
|
||||
BOOST_PYTHON_BINARY_OPERATOR(>=)
|
||||
BOOST_PYTHON_BINARY_OPERATOR(<)
|
||||
BOOST_PYTHON_BINARY_OPERATOR(<=)
|
||||
BOOST_PYTHON_BINARY_OPERATOR(==)
|
||||
BOOST_PYTHON_BINARY_OPERATOR(!=)
|
||||
BOOST_PYTHON_BINARY_OPERATOR(+)
|
||||
BOOST_PYTHON_BINARY_OPERATOR(-)
|
||||
BOOST_PYTHON_BINARY_OPERATOR(*)
|
||||
|
||||
@@ -8,6 +8,24 @@
|
||||
|
||||
namespace boost { namespace python { namespace api {
|
||||
|
||||
# define BOOST_PYTHON_COMPARE_OP(op, opid) \
|
||||
BOOST_PYTHON_DECL object operator op(object const& l, object const& r) \
|
||||
{ \
|
||||
return object( \
|
||||
detail::new_reference( \
|
||||
PyObject_RichCompare( \
|
||||
l.ptr(), r.ptr(), opid)) \
|
||||
); \
|
||||
}
|
||||
BOOST_PYTHON_COMPARE_OP(>, Py_GT)
|
||||
BOOST_PYTHON_COMPARE_OP(>=, Py_GE)
|
||||
BOOST_PYTHON_COMPARE_OP(<, Py_LT)
|
||||
BOOST_PYTHON_COMPARE_OP(<=, Py_LE)
|
||||
BOOST_PYTHON_COMPARE_OP(==, Py_EQ)
|
||||
BOOST_PYTHON_COMPARE_OP(!=, Py_NE)
|
||||
# undef BOOST_PYTHON_COMPARE_OP
|
||||
|
||||
|
||||
#define BOOST_PYTHON_BINARY_OPERATOR(op, name) \
|
||||
BOOST_PYTHON_DECL object operator op(object const& l, object const& r) \
|
||||
{ \
|
||||
|
||||
Reference in New Issue
Block a user