diff --git a/include/boost/python/init.hpp b/include/boost/python/init.hpp index c931d701..03625a1b 100644 --- a/include/boost/python/init.hpp +++ b/include/boost/python/init.hpp @@ -262,7 +262,7 @@ namespace detail { struct count_optionals2 { BOOST_STATIC_CONSTANT( - int, value = boost::mpl::size::value); + int, value = boost::mpl::size::value + 1); }; template @@ -407,9 +407,8 @@ template void define_init(ClassT& cl, InitT const& i, CallPoliciesT const& policies, char const* doc) { - enum { n_defaults_plus_1 = InitT::n_defaults + 1 }; typedef typename InitT::sequence args_t; - detail::define_class_init_helper::apply(cl, policies, args_t(), doc); + detail::define_class_init_helper::apply(cl, policies, args_t(), doc); } }} // namespace boost::python diff --git a/test/defaults.cpp b/test/defaults.cpp index b6d2a72f..0f552666 100644 --- a/test/defaults.cpp +++ b/test/defaults.cpp @@ -91,6 +91,10 @@ struct X { : state(format % make_tuple(a, b, c, d)) {} + X(std::string s, bool b) + : state("Got exactly two arguments from constructor: string(%s); bool(%s); " % make_tuple(s, b)) + {} + object bar(int a, char b = 'D', std::string c = "default", double d = 0.0) const { @@ -162,11 +166,13 @@ BOOST_PYTHON_MODULE_INIT(defaults_ext) # if (!defined(BOOST_INTEL_CXX_VERSION) || BOOST_INTEL_CXX_VERSION > 600) .def(init >()) + .def(init()) # else .def_init(args()) .def_init(args()) .def_init(args()) .def_init(args()) + .def_init(args()) # endif .def("get_state", &X::get_state) .def("bar", &X::bar, X_bar_stubs()) diff --git a/test/defaults.py b/test/defaults.py index 701ba386..aa7602f2 100644 --- a/test/defaults.py +++ b/test/defaults.py @@ -66,6 +66,9 @@ 'int(1); char(K); string(Kim); double(0.0); ' >>> x.bar2(1, 'K', "Kim", 9.9).get_state() 'int(1); char(K); string(Kim); double(9.9); ' +>>> x = X("Phoenix", 1) +>>> x.get_state() +'Got exactly two arguments from constructor: string(Phoenix); bool(1); ' """ def run(args = None):