Correct notes on customising Python builtin comparison operators
Also add example for python:compare feature
This commit is contained in:
parent
3b6f4af15c
commit
4f777b181c
3 changed files with 52 additions and 12 deletions
|
|
@ -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;
|
||||
%}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue