From 577f58149c1e7053a4e84cae89a0bf8b5c7c2ce0 Mon Sep 17 00:00:00 2001 From: Dave Abrahams Date: Sun, 2 Mar 2003 22:11:20 +0000 Subject: [PATCH] tests for operators returning const objects [SVN r17700] --- test/operators.cpp | 15 +++++++++++---- test/operators.py | 3 +++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/test/operators.cpp b/test/operators.cpp index e4ac1e07..9e7a1e5a 100755 --- a/test/operators.cpp +++ b/test/operators.cpp @@ -21,7 +21,13 @@ using namespace boost::python; -typedef test_class<> X; +struct X : test_class<> +{ + typedef test_class<> base_t; + + X(int x) : base_t(x) {} + X const operator+(X const& r) { return X(value() + r.value()); } +}; X operator-(X const& l, X const& r) { return X(l.value() - r.value()); } X operator-(int l, X const& r) { return X(l - r.value()); } @@ -39,17 +45,17 @@ X abs(X x) { return X(x.value() < 0 ? -x.value() : x.value()); } X pow(X x, int y) { - return X(int(pow(double(x.value()), y))); + return X(int(pow(double(x.value()), double(y)))); } X pow(X x, X y) { - return X(int(pow(double(x.value()), y.value()))); + return X(int(pow(double(x.value()), double(y.value())))); } int pow(int x, X y) { - return int(pow(double(x), y.value())); + return int(pow(double(x), double(y.value()))); } std::ostream& operator<<(std::ostream& s, X const& x) @@ -61,6 +67,7 @@ BOOST_PYTHON_MODULE(operators_ext) { class_("X", init()) .def("value", &X::value) + .def(self + self) .def(self - self) .def(self - int()) .def(other() - self) diff --git a/test/operators.py b/test/operators.py index 58ffb5eb..b18d4d2d 100644 --- a/test/operators.py +++ b/test/operators.py @@ -15,6 +15,9 @@ >>> (-y).value() 39 +>>> (x + y).value() +3 + >>> abs(y).value() 39