Skip to content

Commit

Permalink
add a test for lambda as member support
Browse files Browse the repository at this point in the history
  • Loading branch information
nevion committed Aug 16, 2015
1 parent b6a8f44 commit ee20431
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
12 changes: 11 additions & 1 deletion test/class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,28 @@ using namespace boost::python;
struct X
{
int x;
X(int n) : x(n) { }
int foo;
X(int n) : x(n), foo(0){ }
};

int x_function(X& x)
{ return x.x;
}

int y_function(X& x)
{ return x.foo++;
}

BOOST_PYTHON_MODULE(class_ext)
{
class_<X>("X", init<int>());
def("x_function", x_function);
#if (__cplusplus > 199711L) && !defined(BOOST_NO_CXX11_LAMBDAS)
def("y_function", [&foo](int) -> int { return foo++; });
#else
def("y_function", y_function);

#endif
}

#include "module_tail.cpp"
4 changes: 4 additions & 0 deletions test/class.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
>>> x = X(42)
>>> x_function(x)
42
>>> y_function(x)
0
>>> y_function(x)
1
Demonstrate extraction in the presence of metaclass changes:
Expand Down

0 comments on commit ee20431

Please sign in to comment.