I have some C++ methods that have std::set<std::string> as argument or return value.
I would like to map this to a Python frozenset (or regular set) but there does not seem to be a straightforward way to do this.
Does anyone know how one may accomplish this task.
I have some C++ methods that have std::set<std::string> as argument or return value. I
Share
Unfortunately, the standard
indexing_suitefrom Boost.Python does not supportstd::set. There is a indexing_suite v2, that works on all stl containers. (http://mail.python.org/pipermail/cplusplus-sig/2009-July/014704.html)It may not have made it to the official distribution, but you can find it by asking around.
(http://mail.python.org/pipermail/cplusplus-sig/2009-July/014691.html)
I found it to be harder to use then the original
indexing_suite, but it might fit your needs.If that does not work, you can just manually wrap
std::set<std::string>like you would any other class. This will get you astd::set<std::string>into python, where you can turn it into a pythonsetfairly easily.I think that both of those are more work then is called for though. Here is what I would do:
First, wrap the function in C++ with one that has the same signature, but stuffs the returned data in to a
std::vector<std::string>instead of astd::set<std::string>. expose that function rather then the originalNow you have the data in python.
Second, wrap the c++ function in python function that takes the data in that
std::vector<std::string>and stuffs it into a pythonset.Yes, this is rather silly from a design aesthetics point of view, and not the most performant code in the world, but is gets you to where you are going with a minimum of code, and it is fairly robust.