Correct notes on customising Python builtin comparison operators

Also add example for python:compare feature
This commit is contained in:
William S Fulton 2016-08-22 07:22:40 +01:00
commit 4f777b181c
3 changed files with 52 additions and 12 deletions

View file

@ -112,3 +112,19 @@ void Dealloc2Destroyer(PyObject *v) {
}
%}
// Test 5 for python:compare feature
%feature("python:compare", "Py_LT") MyClass::lessThan;
%inline %{
class MyClass {
public:
MyClass(int val = 0) : val(val) {}
bool lessThan(const MyClass& other) const {
less_than_counts++;
return val < other.val;
}
int val;
static int less_than_counts;
};
int MyClass::less_than_counts = 0;
%}