[C++-sig] bp::arg() also requires types to be declared

Niall Douglas s_sourceforge at nedprod.com
Wed Jun 21 18:01:22 CEST 2006

On 21 Jun 2006 at 8:06, Roman Yakovenko wrote:

> > We have a problem therefore. I can only see one should set
> > use_keywords to False on every calldef taking a typed default
> > parameter. Unfortunately, this is most of them and thus renders using
> > bp::arg() useless.
> >
> > Ideas? How hard would it be to patch BPL to let this work usefully?
> Niall, I have an idea, but unfortunately I don't have time to check
> it. Please take a
> look on pyplusplus/module_creator/class_organizer.py file. This file contains
> algorithm - classic topological sort. It is used to define the order of exported
> classes. I am sure you can improve it, so we will not have this problem.

Herein lies a problem:

class Foo;

class Foo2
   friend class Foo;
   Foo2(Foo *f=0);

class Foo
   Foo(Foo2 *f=0);
   inline void somemethod(Foo2 *a) { a->foo(); }

Here you need to declare Foo and Foo2 to BPL. Problem is, they take 
constructor args circularly so if I try to declare default args, 
either one or the other is going to be undeclared to BPL and you get 
the fault.

If, and only if, both Foo and Foo2 have constructors with no default 
args, you can delay the constructor declaration and declare it later 
via bp::init<>. Otherwise you are trapped and can't use bp::arg() at 

To fix pyplusplus to correctly order stuff according to all these 
possibilities, and even then still leaving open the potential of it 
failing to work in certain rare circumstances - well, the correct 
thing to do IMHO is to alter the implementation of bp::arg() so it 
doesn't need to have the type declared to BPL via bp::class_() first.

All this said, I am now out of time for the python bindings. I am 
going to have to cease development once again for the next few 
months. Sorry, I get windows and these windows get exhausted. I must 
now begin on a new chaotic economic modelling software I want to base 
my PhD on.


More information about the Cplusplus-sig mailing list