2
0
mirror of https://github.com/boostorg/python.git synced 2026-01-23 05:42:30 +00:00

Fixed init<...> bug where there are no default arguments. Added a test case for this.

[SVN r15224]
This commit is contained in:
Joel de Guzman
2002-09-09 02:36:54 +00:00
parent ee1cc99c65
commit f8490a8850
3 changed files with 11 additions and 3 deletions

View File

@@ -262,7 +262,7 @@ namespace detail {
struct count_optionals2 {
BOOST_STATIC_CONSTANT(
int, value = boost::mpl::size<typename T::sequence>::value);
int, value = boost::mpl::size<typename T::sequence>::value + 1);
};
template <class T>
@@ -407,9 +407,8 @@ template <class ClassT, class CallPoliciesT, class InitT>
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<n_defaults_plus_1>::apply(cl, policies, args_t(), doc);
detail::define_class_init_helper<InitT::n_defaults>::apply(cl, policies, args_t(), doc);
}
}} // namespace boost::python

View File

@@ -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<int, optional<char, std::string, double> >())
.def(init<std::string, bool>())
# else
.def_init(args<int>())
.def_init(args<int, char>())
.def_init(args<int, char, std::string>())
.def_init(args<int, char, std::string, double>())
.def_init(args<std::string, bool>())
# endif
.def("get_state", &X::get_state)
.def("bar", &X::bar, X_bar_stubs())

View File

@@ -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):