[C++-sig] Py++ and a std::vector of shared_ptrs

Roman Yakovenko roman.yakovenko at gmail.com
Wed Nov 21 22:11:18 CET 2007


On Nov 21, 2007 8:19 PM, Joseph Lisee <jlisee at gmail.com> wrote:

> Hello,
>
> I am trying to wrap a std::vector<boost::shared_ptr<MyType> >, and Py++
> will
> have none of it.  I am using indexing suite version 2, and telling Py++ to
> right
> the module as multiple files.  I exclude everything at the global
> namespace
> level then I find the namespace_t that corresponds to the "sample"
> namespace and
>  include all of it.  When I attempt to compile the resulting files I get
> the
> following error:
>
> Here is the compile error (with lots of "instantiated here", before this):
>
> /opt/ram/local/include/boost-1_34_1/boost/python/suite/indexing/value_traits.hpp
> :56:
> error: no match for 'operator<' in '((const
> boost::shared_ptr<samples::A>*)p1)->boost::shared_ptr<T>::operator* [with
> T =
> samples::A]() < ((const
> boost::shared_ptr<samples::A>*)p2)->boost::shared_ptr<T>::operator* [with
> T =
> samples::A]()'
> scons: ***
>
> [build/wrappers/samples/generated/vector_less_boost_scope_shared_ptr_less_sample
>
> s_scope_A_grate__comma_std_scope_allocator_less_boost_scope_shared_ptr_less_sam
> ples_scope_A_grate___grate___grate_.pypp.os]
> Error 1
>

Py++ is not as smart as it could be :-). The root of the problem is class A,
it doesn't defines operator== and operator<. On the other side indexing
suite v2 is smart enough to understand, that container contains pointers, so
it will not compare pointers but pointee.

I was not aware to this functionality so didn't implemented it.

Solution:
0. to create patch to Py++ to support this functionality :-)))
or
1. add comparison operators to the class ( you can use free operators too )
or
2. disable methods, which require  compare operators:


        f = mb.free_fun( 'funcVectorShared' )
        v = declarations.remove_declarated( f.return_type )
        v.indexing_suite.disable_method( 'sort' )
        v.indexing_suite.disable_method( 'count' )
        v.indexing_suite.disable_method( 'index' )
        v.indexing_suite.disable_method( 'contains' )

HTH

-- 
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20071121/49f66b5c/attachment.htm>


More information about the Cplusplus-sig mailing list