Permalink
Browse files

Merge upstream changes - new repr operator

  • Loading branch information...
2 parents 55421ef + f7ccc9a commit a4c16c540b57512b44bd70cd7525646b69d33a98 @Achimh3011 Achimh3011 committed Apr 2, 2011
Showing with 7 additions and 4 deletions.
  1. +6 −4 07-Operators/operators.cpp
  2. +1 −0 07-Operators/operators.py
@@ -7,16 +7,17 @@ class NumberLike
NumberLike(int n = 0) : _n(n) {}
NumberLike& operator+= (int i)
{ _n += i; return *this; }
- std::string toString() const
- { std::stringstream s; s<<_n; return s.str(); }
+ std::string str() const
+ { std::stringstream s; s << _n; return s.str(); }
+ std::string repr() const
+ { std::stringstream s; s << "NumberLike("<< _n<<")"; return s.str(); }
private:
int _n;
};
NumberLike operator+(NumberLike n, int i)
{ n += i; return n; };
-
#include <boost/python.hpp>
using namespace boost::python;
@@ -26,6 +27,7 @@ BOOST_PYTHON_MODULE(operators)
class_<NumberLike>("NumberLike")
.def(init< optional<int> >())
.def(self + int())
- .def("__str__", &NumberLike::toString)
+ .def("__str__", &NumberLike::str)
+ .def("__repr__", &NumberLike::repr)
;
}
@@ -9,3 +9,4 @@
n0 = NumberLike()
m0 = n0 + 1
print m0
+

0 comments on commit a4c16c5

Please sign in to comment.