diff options
author | Lorry Tar Creator <lorry-tar-importer@baserock.org> | 2013-06-25 22:59:01 +0000 |
---|---|---|
committer | <> | 2013-09-27 11:49:28 +0000 |
commit | 8c4528713d907ee2cfd3bfcbbad272c749867f84 (patch) | |
tree | c09e2ce80f47b90c85cc720f5139089ad9c8cfff /libs/python/test/raw_ctor.cpp | |
download | boost-tarball-baserock/morph.tar.gz |
Imported from /home/lorry/working-area/delta_boost-tarball/boost_1_54_0.tar.bz2.boost_1_54_0baserock/morph
Diffstat (limited to 'libs/python/test/raw_ctor.cpp')
-rw-r--r-- | libs/python/test/raw_ctor.cpp | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/libs/python/test/raw_ctor.cpp b/libs/python/test/raw_ctor.cpp new file mode 100644 index 000000000..a825ae019 --- /dev/null +++ b/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 <boost/python/class.hpp> +#include <boost/python/raw_function.hpp> +#include <boost/python/make_constructor.hpp> +#include <boost/python/dict.hpp> +#include <boost/python/tuple.hpp> +#include <boost/python/module.hpp> + +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>("Foo", no_init) + .def("__init__", raw_function(&init_foo)) + .def(init<tuple, dict>()) + .def_readwrite("args", &Foo::args) + .def_readwrite("kw", &Foo::kw) + ; +} + +#include "module_tail.cpp" |