From 19fcec84d8d7d21e796c7624e521b60d28ee21ed Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 20:45:59 +0200 Subject: Adding upstream version 16.2.11+ds. Signed-off-by: Daniel Baumann --- src/boost/libs/python/test/raw_ctor.cpp | 43 +++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/boost/libs/python/test/raw_ctor.cpp (limited to 'src/boost/libs/python/test/raw_ctor.cpp') diff --git a/src/boost/libs/python/test/raw_ctor.cpp b/src/boost/libs/python/test/raw_ctor.cpp new file mode 100644 index 000000000..a825ae019 --- /dev/null +++ b/src/boost/libs/python/test/raw_ctor.cpp @@ -0,0 +1,43 @@ +// Copyright David Abrahams 2004. Distributed under the Boost +// Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include +#include +#include +#include +#include +#include + +using namespace boost::python; + +class Foo +{ + public: + Foo(tuple args, dict kw) + : args(args), kw(kw) {} + + tuple args; + dict kw; +}; + +object init_foo(tuple args, dict kw) +{ + tuple rest(args.slice(1,_)); + return args[0].attr("__init__")(rest, kw); +} + +BOOST_PYTHON_MODULE(raw_ctor_ext) +{ + // using no_init postpones defining __init__ function until after + // raw_function for proper overload resolution order, since later + // defs get higher priority. + class_("Foo", no_init) + .def("__init__", raw_function(&init_foo)) + .def(init()) + .def_readwrite("args", &Foo::args) + .def_readwrite("kw", &Foo::kw) + ; +} + +#include "module_tail.cpp" -- cgit v1.2.3