1 // Copyright David Abrahams 2004. Distributed under the Boost
2 // Software License, Version 1.0. (See accompanying
3 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
4 
5 #include <boost/python/class.hpp>
6 #include <boost/python/raw_function.hpp>
7 #include <boost/python/make_constructor.hpp>
8 #include <boost/python/dict.hpp>
9 #include <boost/python/tuple.hpp>
10 #include <boost/python/module.hpp>
11 
12 using namespace boost::python;
13 
14 class Foo
15 {
16  public:
Foo(tuple args,dict kw)17     Foo(tuple args, dict kw)
18       : args(args), kw(kw) {}
19 
20     tuple args;
21     dict kw;
22 };
23 
init_foo(tuple args,dict kw)24 object init_foo(tuple args, dict kw)
25 {
26     tuple rest(args.slice(1,_));
27     return args[0].attr("__init__")(rest, kw);
28 }
29 
BOOST_PYTHON_MODULE(raw_ctor_ext)30 BOOST_PYTHON_MODULE(raw_ctor_ext)
31 {
32     // using no_init postpones defining __init__ function until after
33     // raw_function for proper overload resolution order, since later
34     // defs get higher priority.
35     class_<Foo>("Foo", no_init)
36         .def("__init__", raw_function(&init_foo))
37         .def(init<tuple, dict>())
38         .def_readwrite("args", &Foo::args)
39         .def_readwrite("kw", &Foo::kw)
40         ;
41 }
42 
43 #include "module_tail.cpp"
44