[C++-sig] dumb policy question

John Arbash Meinel john at arbash-meinel.com
Tue Jan 31 17:22:37 CET 2006


Grant Goodyear wrote:
> Okay, so I read through the FAQ again and see "How can I wrap
> functions which take C++ containers as arguments", from which I 
> gather that the answer is "it's really darn hard, and probably 
> not worth the effort", if I understand it correctly.
> 
> Hmmm.
> -Grant-

I usually export std::vector<int> into python. With something like this:

scope outer = class_<Vec, boost::noncopyable>("Vec", no_init);
class_< std::vector<signed char> >("i8")
  .def(vector_indexing_suite< std::vector<signed char> >())
;
class_< std::vector<unsigned char> >("ui8")
  .def(vector_indexing_suite< std::vector<unsigned char> >())
;

...

Then the vectors I care about are available as:

import libpyref
v = libpyref.Vec.i32()
v.append(0)
v.append(0)
v.append(0)

libpyref.ref(v, 2)

I don't know if that helps you or not, but it is how I solved the problem.

John
=:->

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 252 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20060131/13950831/attachment.pgp>


More information about the Cplusplus-sig mailing list