[C++-sig] tuple, list, dict, et. al

David Abrahams david.abrahams at rcn.com
Wed Jun 26 21:35:19 CEST 2002


From: "Ralf W. Grosse-Kunstleve" <rwgk at yahoo.com>


> --- David Abrahams <david.abrahams at rcn.com> wrote:
> > So, I'm back to my earlier position: we can have sequence_fast for
people
> > who want something that converts to a tuple (or preserves a list), but
I
> > want sequence for people who want to accept any sequence without
modifying
> > it.
>
> This sounds to me as if you want a wrapper for the family of API
functions
> listed here:
>
> http://www.python.org/doc/current/api/sequence.html

No, we already have what we need as far as API with object. All of these
other classes (tuple, string, dict, sequence) I'm discussing should just be
classes derived from object, with appropriate constructors invoking the
corresponding built-in type on the argument to get the argument for the
base class constructor. The only other step is to make the appropriate
client-side to/from_python converters. These should probably be handled as
specializations, as was done for object and its proxies.

I would consider adding some optimizations for particular types (e.g. use
PyString_Concat to implement operator+ on strings), but it seems
unneccessary as the existing object interfaces already work, and a little
dangerous in the case of in-place operators. If the type's in-place op ever
returned an object of a different type, a python::string could end up
wrapping some other python type, for example.


> At first sight this looks straight-forward. Do you see major
difficulties?

No, I think it is straightforward... just not the same way you suggested
;-)

-Dave







More information about the Cplusplus-sig mailing list