2
0
mirror of https://github.com/boostorg/python.git synced 2026-01-24 18:12:43 +00:00

tests for operators returning const objects

[SVN r17700]
This commit is contained in:
Dave Abrahams
2003-03-02 22:11:20 +00:00
parent 4b97e191b8
commit 577f58149c
2 changed files with 14 additions and 4 deletions

View File

@@ -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>("X", init<int>())
.def("value", &X::value)
.def(self + self)
.def(self - self)
.def(self - int())
.def(other<int>() - self)

View File

@@ -15,6 +15,9 @@
>>> (-y).value()
39
>>> (x + y).value()
3
>>> abs(y).value()
39