[C++-sig] python sequence to stl container
david.abrahams at rcn.com
Fri Jun 28 20:50:47 CEST 2002
----- Original Message -----
From: "Martin Casado" <casado2 at llnl.gov>
> Is it not possible to change the rvalue conversion protocol so that
> the check to see if the object is convertible and the conversion
> happen within construct() since it already has access to the
That's almost the same thing, but it wouldn't be a good idea. Most
conversions should do just a little work to check for convertibility and
defer all of the actual work until the overload is actually chosen.
> The problem I suppose is signifying that
> the object is not convertible, using exceptions would almost certainly
> be too slow. Do you have some ideas about how you were going to go
> about this?
Yeah, it's pretty straightforward.
1. from_python_stage1_data would acquire a PyObject* member which would
store the source object
2. The protocol for the convertible() function of rvalue from_python
conversion servers would be to take a pointer to from_python_stage1_data
instead of the PyObject* -- they can retrieve the PyObject* from the data.
3. If they want to they can downcast to rvalue_data<T>* and construct the
result object in-place, returning the pointer to storage to indicate
4. As a nice side-effect, the construct() protocol no longer needs a
PyObject* argument, and the protocol for client-side converters' operator()
Ready to go and implement it?
If not, I'm happy to trade that for another task...
More information about the Cplusplus-sig