2
0
mirror of https://github.com/boostorg/python.git synced 2026-01-19 04:22:16 +00:00

Fixes from Christoph Ludwig <cludwig-at-cdc.informatik.tu-darmstadt.de>

[SVN r25577]
This commit is contained in:
Dave Abrahams
2004-10-05 20:41:12 +00:00
parent e888d8aa88
commit a97d050016

View File

@@ -7,16 +7,23 @@
#include <boost/python/module.hpp>
#include <boost/python/def.hpp>
#include "test_class.hpp"
#include <boost/python/module.hpp>
#include <boost/python/class.hpp>
#include <boost/python/operators.hpp>
#include <boost/operators.hpp>
//#include <boost/python/str.hpp>
// Just use math.h here; trying to use std::pow() causes too much
// trouble for non-conforming compilers and libraries.
#include <math.h>
#if __GNUC__ != 2
# include <ostream>
#else
# include <ostream.h>
#endif
// Just use math.h here; trying to use std::pow() causes too much
// trouble for non-conforming compilers and libraries.
#include <math.h>
using namespace boost::python;
using namespace boost::python;
@@ -65,6 +72,35 @@ std::ostream& operator<<(std::ostream& s, X const& x)
return s << x.value();
}
struct number
: boost::integer_arithmetic<number>
{
explicit number(long x_) : x(x_) {}
operator long() const { return x; }
template <class T>
number& operator+=(T const& rhs)
{ x += rhs; return *this; }
template <class T>
number& operator-=(T const& rhs)
{ x -= rhs; return *this; }
template <class T>
number& operator*=(T const& rhs)
{ x *= rhs; return *this; }
template <class T>
number& operator/=(T const& rhs)
{ x /= rhs; return *this; }
template <class T>
number& operator%=(T const& rhs)
{ x %= rhs; return *this; }
long x;
};
BOOST_PYTHON_MODULE(operators_ext)
{
class_<X>("X", init<int>())
@@ -78,6 +114,7 @@ BOOST_PYTHON_MODULE(operators_ext)
.def(self < self)
.def(1 < self)
.def(self -= self)
.def(abs(self))
.def(str(self))
@@ -94,6 +131,40 @@ BOOST_PYTHON_MODULE(operators_ext)
)
;
class_<number>("number", init<long>())
// interoperate with self
.def(self += self)
.def(self + self)
.def(self -= self)
.def(self - self)
.def(self *= self)
.def(self * self)
.def(self /= self)
.def(self / self)
.def(self %= self)
.def(self % self)
// Convert to Python int
.def(int_(self))
// interoperate with long
.def(self += long())
.def(self + long())
.def(long() + self)
.def(self -= long())
.def(self - long())
.def(long() - self)
.def(self *= long())
.def(self * long())
.def(long() * self)
.def(self /= long())
.def(self / long())
.def(long() / self)
.def(self %= long())
.def(self % long())
.def(long() % self)
;
class_<test_class<1> >("Z", init<int>())
.def(int_(self))
.def(float_(self))