Thanks, it works flawlessly.

Sincerly,

Helfer Thomas

----- Mail original -----
De: "Jim Bosch" <tallji...@gmail.com>
À: cplusplus-sig@python.org
Envoyé: Vendredi 13 Janvier 2012 17:15:27
Objet: Re: [C++-sig] trouble using vector of shared_ptr using boost python

On 01/13/2012 03:13 AM, helfertho...@free.fr wrote:
> Hi,
>
> In the following test, we wrap a class "A" (and the class shared_ptr<A>  
> using boost python facilites) and a function returning a vector of shared_ptr 
> of this class (see test.cxx). The class "A" provides a display method. 
> Creating an object of type "A" and calling the display method just works as 
> expected.
>
> The trouble (see test.py) is that calling the "display" method when iterating 
> over the elements of the vector (of shared_ptr...) leads to the following 
> message :
>
> Traceback (most recent call last):
>    File "test.py", line 5, in<module>
>      i.display()
> Boost.Python.ArgumentError: Python argument types in
>      A.display(A)
> did not match C++ signature:
>      display(A {lvalue})
>
> Can anybody tell me if I misused the library ?
>

It looks like vector_indexing_suite isn't smart enough to figure out it 
shouldn't return a proxy object for a vector of shared_ptr.

This snippet should solve your problem:

class_<vector<shared_ptr<A> > >("AVector")
   .def(vector_indexing_suite<vector<shared_ptr<A> >, true >());
                                                      ^^^^

That sets the vector_indexing_suite's NoProxy template parameter to 
"true".  I believe those proxies only exist to keep the container's 
elements from becoming dangling references in Python, which isn't 
necessary for containers of shared_ptr.

Jim
_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig
_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig

Reply via email to