[C++-sig] Re: will custom lvalue converters be supported?

Igor Lapshin igor at pcigeomatics.com
Wed Jul 21 17:14:54 CEST 2004


Hi Ralf and Dave, 

Thanks for the fast response.

That's exactly the case:  there are already hundreds of functions
written with that "write-back" requirement long before we decided to use
Python and it seems to me that writing thin wrappers for all of them is
quite problematic. Moreover, the new functions are still being
written...

The classes, which are used as parameters for those functions, derived
from stl::vector, but have additional member-functions, which I cannot
remove without affecting hundreds of already written functions. Those
additional members are used only internally and not from Python, thus
tuple or sequence functionality is sufficient. I can add new
member-functions, or derive new classes from existing. The current
classes normally don't hold more than 10-100 values and, by convention,
are sent to the functions by references (thus, the function can change
them). As I understand, I have now two options: 

 - don't allow returning values in arguments at all, but that would make
many existing functions unusable;

 - don't do automatic conversions and request that all classes be
instantiated explicitly (what looks ugly to me):

  C++:
      Class CustomVectorInt : public std::vector<int>
	{ ... } // expands vector<int> operations

	int fn(CustomVectorInt &cv1, CustomVectorInt &cv2,.. cvN)
	{
 	  cv1+=cv2; // cv1 is expected to be returned to the caller
	  return 0; // no error
	}

  Python:
	cv1=CustomVectorInt()
	cv1[:]= [1,2,3]
	fn(cv1, cv2, cv3, cv4...) # many functions have >10 parameters
	returnedpythonlist=cv1.to_list() # I'll add conversion function

Am I right?

Is there any way to write a generic thin wrapper supporting "write back"
for various functions with different signatures but with very limited
set of types (we have some 5 types)?

Thanks,
Igor


$-> > > I am wondering if custom lvalue converters are planned to be
$-> supported
$-> > > in near future.
$-> >
$-> > There are no such plans.
$-> >
$-> > > The FAQ say that they are not supported, but I found some
$-> > > declarations in Python.Boost source code, which look as relevant
to
$-> > > lvalue conversions, e.g. void* get_lvalue_from_python().
$-> >
$-> > There's nothing in Boost.Python that would allow the example to
work.
$-> >
$-> > > I have almost exactly the situation as it is described in FAQ
(but
$-> > > with my custom classes):
$-> >
$-> > What does the parenthetical remark mean?  Maybe that small
difference
$-> > means you don't need what's being discussed there.
$-> 
$-> ... and if you really need the behavior outlined in the FAQ you
could
$-> write a
$-> thin wrapper with boost::python::list in the signature. This is a
$-> problem only
$-> if you have a large number of functions with a "write back"
requirement.
$-> 
$-> Ralf
$-> 
$-> 
$-> 
$-> 
$-> __________________________________
$-> Do you Yahoo!?
$-> New and Improved Yahoo! Mail - 100MB free storage!
$-> http://promotions.yahoo.com/new_mail
$-> _______________________________________________
$-> C++-sig mailing list
$-> C++-sig at python.org
$-> http://mail.python.org/mailman/listinfo/c++-sig




More information about the Cplusplus-sig mailing list