[C++-sig] copy.deepcopy of a vector, and the resulting error
Matthew Scouten
matthew.scouten at gmail.com
Tue Feb 5 21:41:58 CET 2008
So I have a vector of foo that I exposed with the indexing suite, and I need
to deepcopy it. I get a Boost.Python.ArgumentError exception when I try to
iterate across the result later.
>>> from BusyBox import *
>>> foo
<class 'BusyBox.foo'>
>>> vecfoo
<class 'BusyBox.vecfoo'>
>>> vf = vecfoo()
>>> vf.append(foo())
>>> vf.append(foo())
>>> vf.append(foo())
>>> vf.append(foo())
>>> vf.append(foo())
>>> vf.append(foo())
>>> vf.append(foo())
>>> vf.append(foo())
>>> vf.append(foo())
>>> vf.append(foo())
>>> vf.append(foo())
>>> vf.append(foo())
>>> vf.append(foo())
>>> vf.append(foo())
>>> vf.append(foo())
>>> vf.append(foo())
>>> for f in vf:
... f.__repr__()
...
'<BusyBox.foo object at 0x00A81EF0>'
'<BusyBox.foo object at 0x00A81F70>'
'<BusyBox.foo object at 0x00A81EF0>'
'<BusyBox.foo object at 0x00A81F70>'
'<BusyBox.foo object at 0x00A81EF0>'
'<BusyBox.foo object at 0x00A81F70>'
'<BusyBox.foo object at 0x00A81EF0>'
'<BusyBox.foo object at 0x00A81F70>'
'<BusyBox.foo object at 0x00A81EF0>'
'<BusyBox.foo object at 0x00A81F70>'
'<BusyBox.foo object at 0x00A81EF0>'
'<BusyBox.foo object at 0x00A81F70>'
'<BusyBox.foo object at 0x00A81EF0>'
'<BusyBox.foo object at 0x00A81F70>'
'<BusyBox.foo object at 0x00A81EF0>'
'<BusyBox.foo object at 0x00A81F70>'
>>> import copy
>>> vf2 = copy.deepcopy(vf)
>>> for f in vf2:
... f.__repr__()
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
Boost.Python.ArgumentError: Python argument types in
vecfoo.__iter__(vecfoo)
did not match C++ signature:
__iter__(struct boost::python::back_reference<class std::vector<struct
foo,class std::allocator<struct foo> > &>)
>>>
here is my c++ code:
struct foo
{
foo(){} ;
foo(int init_x, int init_y){x=init_x;y=init_y;};
int x;
int y;
bool operator==(const foo &rhs) const;
};
bool foo::operator==(const foo &rhs) const {return (this == &rhs);}
struct foo_wrapper : foo , wrapper<foo>
{
foo_wrapper();
foo_wrapper(const foo& f);
foo_wrapper(int init_x, int init_y);
static bool eq(const foo& lhs, const foo &rhs);
};
foo_wraper::foo_wrapper(const foo& exch): foo(exch), wrapper<foo>(){}
foo_wrapper::foo_wrapper(): foo(), wrapper<foo>(){}
foo_wrapper::foo_wrapper(int init_x, int init_y) : foo(init_x,init_y),
wrapper<foo>(){}
bool foo_wrapper::eq(const foo& lhs, const foo &rhs) {return (lhs == rhs);}
Later:
class_<foo_wrapper>("foo")
.def(init<>())
.def(init<int, int>())
.def_readwrite("x", &foo::x )
.def_readonly ("y", &foo::y )
.def("__eq__", &foo_wrapper::eq)
;
class_<std::vector<foo> > ("vecfoo")
.def(vector_indexing_suite< std::vector<foo>, true >() );
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20080205/362acbb4/attachment.htm>
More information about the Cplusplus-sig
mailing list