[C++-sig] Default arguments in pyplusplus

Roman Yakovenko roman.yakovenko at gmail.com
Sun Jun 18 19:41:08 CEST 2006

On 6/18/06, Niall Douglas <s_sourceforge at nedprod.com> wrote:
> Hmm, pyplusplus doesn't tell BPL about default arguments at all!

Niall, I just added the tests that check your statement. I can not reproduce
the behaviour you are talking about.

namespace default_args{

struct data{
    int sum( int i=0 ){ return i; }
    int sum( int i, int j, int k=3 ){ return i + j + k; }


pyplusplus will generate next code:

namespace bp = boost::python;

    bp::class_< default_args::data >( "data" )
                , (int ( ::default_args::data::* )( int ) )(
&::default_args::data::sum )
                , ( bp::arg("i")=0 )
                , bp::default_call_policies() )
                , (int ( ::default_args::data::* )( int,int,int ) )(
&::default_args::data::sum )
                , ( bp::arg("i"), bp::arg("j"), bp::arg("k")=3 )
                , bp::default_call_policies() );

My test is next:

d = module.data()
self.failUnless( d.sum() == 0 )
self.failUnless( d.sum( 1, 2 ) == 6 )

I would like to see your use case

> Surely it should output BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS() for
> each overloaded function?

BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS has limit: it can not be used
for functions that takes different type of arguments:

double sum( int );
double sum( double, double );

You can't not expose them using the macro.

> Needless to say, the TnFOX python bindings won't work without default
> arguments working :(

I agree with you, may be you have some where in the code use_keywords = False?

> I did try adding this on my own, but it's complex. I'm afraid the
> class hierarchy in pyplusplus is fairly complex, complex enough that
> without a debugger it's hard to modify. So I'll have to leave it to
> you Roman!

Please provide test case and I will try to fix ASAP.

Roman Yakovenko
C++ Python language binding

More information about the Cplusplus-sig mailing list