Improve cpp11_function_objects test for python
This commit is contained in:
parent
78b904764a
commit
aeacff3b14
2 changed files with 23 additions and 6 deletions
|
|
@ -3,25 +3,31 @@
|
|||
Function objects are objects which overload the operator() function.
|
||||
The std::function does not provide any seamless support in the target languages yet.
|
||||
*/
|
||||
%module cpp11_function_objects
|
||||
%module(directors="1") cpp11_function_objects
|
||||
|
||||
%rename(__call__) Test::operator();
|
||||
|
||||
%feature("director") Test;
|
||||
|
||||
%inline %{
|
||||
struct Test {
|
||||
class Test {
|
||||
public:
|
||||
int value;
|
||||
|
||||
void operator()(int x, int y) {
|
||||
virtual void operator()(int x, int y) {
|
||||
value=x+y;
|
||||
}
|
||||
Test() : value(0) {}
|
||||
} test;
|
||||
~Test() {}
|
||||
};
|
||||
|
||||
Test test;
|
||||
|
||||
#include <functional>
|
||||
std::function<void ( int, int )> pF = test;
|
||||
|
||||
int testit1(Test new_test, int a, int b) {
|
||||
pF = new_test;
|
||||
int testit1(Test &new_test, int a, int b) {
|
||||
pF = std::ref(new_test);
|
||||
pF(a, b);
|
||||
return new_test.value;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue