[C++-sig] Re: indexing_v2 status update

Ralf W. Grosse-Kunstleve rwgk at yahoo.com
Tue Nov 25 02:39:02 CET 2003


--- Raoul Gough <RaoulGough at yahoo.co.uk> wrote:
> >> and should I try adding the iterator-based constructor support?
> >
> > IMO yes, but my opinion isn't strongly-held.

I think it is really important.

> I guess the real question is how to do it. I'll start looking into it
> a bit deeper, but I suspect I'll need some advice. Converting the
> Python iterable object to two C++ iterators isn't hard, but I don't
> know how to create the forwarding function and a sensible __iter__
> overload that gets called (only) when appropriate. The problem is that
> there will be other container constructors that really do take just a
> single parameter, so how can the code decide whether to try one of
> them or whether to try making two C++ iterators out of the parameter.
> 
> For one thing, it would be good if the code could use the normal copy
> constructor if passed a wrapped C++ object of the same type, or at
> least use C++ iterators directly rather than going through a C++
> wrapper of a Python iterator that is actually a C++ iterator (C++ ->
> Python -> C++ dispatching). I don't know how realistic that idea is.

This sounds overly complicated to me. I believe you could get the job done in
relatively little time if you started with the container conversions header
from the scitbx:

http://cvs.sourceforge.net/viewcvs.py/cctbx/scitbx/include/scitbx/boost_python/container_conversions.h?rev=1.10&view=auto

Put the code in another namespace, remove to_tuple and the tuple_mapping*
convenience templates. Instantiate from_python_sequence<> when a vector-style
container is wrapped. Also automatically wrap the copy constructor of that
vector-style container.

My meta-programming is not very advanced. Therefore I dare suggesting that the
from_python_sequence<> template and the copy consturctor should only be
instantiated if the user supplies one of the policies (call them
FromPythonSequencePolicies).

Don't get side-tracked by performance considerations. If someone constructs a
container from Python slow performance is expected. What counts for the Python
programmer is convenience and flexibility. If you make it easy to wrap C++
containers users can quickly implement time-critical functions in C++.

Ralf


__________________________________
Do you Yahoo!?
Free Pop-Up Blocker - Get it now
http://companion.yahoo.com/




More information about the Cplusplus-sig mailing list