[C++-sig] Py++ module for code with protected operator=

Maciej Sitarz macieksitarz at wp.pl
Sun Mar 21 09:06:59 CET 2010


On 21.03.2010 06:07, Roman Yakovenko wrote:
> On Sat, Mar 20, 2010 at 11:10 PM, Maciej Sitarz<macieksitarz at wp.pl>  wrote:
>> Just one more comment...
>>
>> The constructor takes reference to vector<JobPropertyWrapper>, so I suspect
>> that maybe it will be filled there by some other code I don't have? So I
>> don't need to fill the vector, just to create it (I will ask the developers)
>
> Right, you'd better talk with them. Boost.Python allows to export
> libraries without touching them, but sometimes a small library change
> could make you task easier.

Yes, it works, because there's no code generated for std::vector<item_t>
Try adding this function to item_t class:
void fund( std::vector<item_t>& v) { }

And then it doesn't compile successfully.

When I comment this line from the generated code:
vector_less__item_t__greater__exposer.def( bp::indexing::vector_suite< 
std::vector< item_t > >() );
it compiles and appears to work, but I can't figure out how to pass a 
list/vector to that function:


import test
item = test.item_t( 10 )
vect = [test.item_t(1), test.item_t(2)]
item.fund(vect)
---------------------------------------------------------------------------
ArgumentError                             Traceback (most recent call last)

/home/macieks/error_examples/protected_assign/<ipython console>

ArgumentError: Python argument types in
     item_t.fund(item_t, list)
did not match C++ signature:
     fund(item_t {lvalue}, std::vector<item_t, std::allocator<item_t> > 
{lvalue} v)

In [5]: vect
Out[5]:
[<test.item_t object at 0x7f8f38899e10>,
  <test.item_t object at 0x7f8f38899d60>]

In [6]: vect?
Type:           list
Base Class:     <type 'list'>
String Form:    [<test.item_t object at 0x7f8f38899e10>, <test.item_t 
object at 0x7f8f38899d60>]
Namespace:      Interactive
Length:         2
Docstring:
     list() -> new list
     list(sequence) -> new list initialized from sequence's items

I'm not sure, but that should work, shouldn't it?

-- 
Maciek Sitarz


More information about the Cplusplus-sig mailing list