[C++-sig] constructor wrappers?

Ralf W. Grosse-Kunstleve rwgk at yahoo.com
Thu May 30 20:31:21 CEST 2002

--- David Abrahams <david.abrahams at rcn.com> wrote:
> I understand the goal, but I'm not sure what you've got there is the best
> solution, for two reasons:
> 1. It incurs the cost of copying "any"
> 2. It requires the ability to copy "any", and not all class types are
> copyable.

In the vast majority of cases (and there were many) where I was craving for a
light-weight method of defining additional Python-specific constructors both 1.
and 2. are not a problem. (Almost all my types are tiny. For large arrays I use
a reference counted look-alike of std::vector.)

> Currently, the way to do this is with a class derived from any:
>     boost::python::class_<any,any_wrapper>("any")
>         .def_init(args<PyObject*>()) // could use args<tuple> soon
> Where
>     any_wrapper::any_wrapper(PyObject* ignored, PyObject* seq)
> is defined.

This seems to resemble what I did in V1. I would call this the heavy-weight
alternative. In practice I have often shied away from this in favor of simpler
but more klunky approaches. IMO the average user would be much better served
with the light-weight alternative because it requires less code and, almost
more importantly, is easier to understand.

> However, I'm open to other interface suggestions. I suggest you take a look
> at the documentation for make_constructor and the Holder concept to get
> started.

I will have a look.

> Also, part of the formula may involve some extensions to the CallPolicies
> concept. For example, we might want to make it possible to specify the
> from_python converter that gets used for each argument.

For a start I would be happy with the famous "70% solution." Add more
sophistication depending on user demand.


Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup

More information about the Cplusplus-sig mailing list