[C++-sig] std::vector

Scott A. Smith ssmith at magnet.fsu.edu
Thu Oct 3 15:18:18 CEST 2002


Hi Ralf,

> I could dig out some old stuff that I used with Boost.Python v1, 
> but I highly
> recommend using Boost.Python v2. Is that a possibility?

Quite frankly, I don't know. It is not clear to me how one uses/builds
version 2 versus version 1 yet. I there a way to see what version the
Boost.Python library is? I am pretty sure that at the moment I am using
1.28, but I did build the cvs version few months back. At that time
I remember I was confused over which version I was actually building.
Didn't it depend upon what directory jam was invoked from or something
like that? I'll look over the old messages to see if I can make sense out
of things, and try to build/switch to v2. Hopefully it will be
compatible with what I have done so far. I guess I need to
update my Boost stuff from CVS? Then (since I only need Boost.Python at
the moment), does it still matter what directory I start the build from?

It would be great if I can get vectors, lists, etc. working smoothly.
Your (& Dave's) help is and has been much appreciated.

Scott
 

> I have been reading the documentation on dealing with std::vector<> in
> Boost.Python, 
> http://www.boost.org/libs/python/doc/cross_module.html, and
> this is exactly what I need for both vectors of built-in 
> types and those
> using my own classes. I have used the class builder to expose such a
> vector
> as a Python object and now need to be able to go back and 
> export some C++
> functions that use them as arguments or as a return type.
>
> Is there a module already in Boost.Python that has 
> "std_vector"? I cannot
> find anything on it and the html page above only supposes that one had
> such
> a module. I think it would help me out quite a bit if I could 
> play with
> some
> vector<int> functions to try out what is suggested. Even 
> more, if some of
> this is already in Boost.Python I would surely like to use it 
> rather than
> begin doing so for all the class types I am using with std::vector.
>
> For example, I have this to expose my std::vector<std::string>:
>
>     boost::python::class_builder<std::vector<std::string> >
> Vstring(PyModule, "Vstring");
>     Vstring.def(boost::python::constructor<>());
>     Vstring.def(Vstring_push_back, "push_back");
>
> and this allows me to make objects of Vstring in Python just fine. The
> push_back stuff is done as shown in the comprehensive test. 
> Now, how do I get
>
> VS = Vstring()
> VS = MyFunctionReturningStdVectorOfStrings()
> MyFunctionUsingStdVectorOfStrings(VS)
>
> by exporting C++ functions that are something like
>
> std::vector<std::string> MyFunctionReturningStdVectorOfStrings();
> void MyFunctionUsingStdVectorOfStrings(std::vector<std::string>);
>
> to work in Python. Do I need import_converters/export_converters? Do I
> need
> them even when everything is in the same module? Neither the
> "vector_double"
> nor "string_map" in the comprehensive test show this and 
> AFAIK the test
> does
> have any code where C++ functions using and returning 
> std::vector<double>
> are exported and making use of vector_double.
>
> Is there other documentation on this, or perhaps a place where I can
> easily
> search for such info?





More information about the Cplusplus-sig mailing list