[C++-sig] Container Conversions: Wrapping Functions ExpectingNon-const References

Bilokon, Paul paul.bilokon at lehman.com
Wed Aug 27 13:01:36 CEST 2008


Hi Ralf,

Many thanks for your explanation. I see there are two options:
on-the-fly converters without write-back and wrappers (a la the vector
indexing suite, or perhaps the set wrapper).

In essence, the former can be used for passing values, the latter for
passing references.

I have also tried adding conversions for a few simple types (e.g.
std::pairs and boost::tuples) to see how they work. Looks like they do
the trick.

Many thanks,
Paul

-----Original Message-----
From: c++-sig-bounces+paul.bilokon=lehman.com at python.org
[mailto:c++-sig-bounces+paul.bilokon=lehman.com at python.org] On Behalf Of
Ralf W. Grosse-Kunstleve
Sent: Monday, August 25, 2008 10:49 AM
To: Development of Python/C++ integration
Subject: Re: [C++-sig] Container Conversions: Wrapping Functions
ExpectingNon-const References

Hi Paul,




> Here I have difficulties:
> 
> Boost.Python.ArgumentError: Python argument types in
>     ContainersExample2.doubleVectorOfInts(ContainersExample2, list) 
> did not match C++ signature:
>     doubleVectorOfInts(class ContainersExample2 {lvalue}, class 
> std::vector<int,class std::allocator<int> > {lvalue})
>
> What's the recommended technique(s) for this situation?

Boost.Python doesn't have "on-the-fly converters with write-back" (long
story).

You have to wrap std::vector<int> "properly" if you want to pass
non-const references to C++.
The vector-indexing suite is an option that should work well. Or you can
follow this more minimalistic example:


http://cctbx.svn.sourceforge.net/viewvc/cctbx/trunk/scitbx/stl/vector_wr
apper.h?view=markup

Ignore the ref_from_array code near the bottom.

Ralf
_______________________________________________
C++-sig mailing list
C++-sig at python.org
http://mail.python.org/mailman/listinfo/c++-sig
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

This message is intended only for the personal and confidential use of the designated recipient(s) named above.  If you are not the intended recipient of this message you are hereby notified that any review, dissemination, distribution or copying of this message is strictly prohibited.  This communication is for information purposes only and should not be regarded as an offer to sell or as a solicitation of an offer to buy any financial product, an official confirmation of any transaction, or as an official statement of Lehman Brothers.  Email transmission cannot be guaranteed to be secure or error-free.  Therefore, we do not represent that this information is complete or accurate and it should not be relied upon as such.  All information is subject to change without notice.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: StdPairConversions.h
Type: application/octet-stream
Size: 3270 bytes
Desc: StdPairConversions.h
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20080827/2f87e02b/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: BoostTupleConversions.h
Type: application/octet-stream
Size: 22972 bytes
Desc: BoostTupleConversions.h
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20080827/2f87e02b/attachment-0001.obj>


More information about the Cplusplus-sig mailing list