[C++-sig] Exposing a generic template system in Boost.Python

Francesco Biscani bluescarni at gmail.com
Wed Mar 19 18:23:47 CET 2014


Greetings,

I have been trying to think of a solution about this for a few days now,
but I did not get very far.

I am exposing specific instances of C++ template classes using
Boost.Python. Let's say for the sake of argument that I am exposing
std::vector<of-a-few-types>. What I would like to achieve on the Python
side would be some kind of unified interface of this kind:

# Define a vector-of-ints type.
vec_int = vector["int"]
# Define a vector-of-doubles type.
vec_float = vector["double"]
...

etc., possibly with exceptions being raised if a template type which has
not been exposed is requested. Additionally, the system should
automagically work with nested generic types:

# Define a vector-of-vectors-of-ints type.
vec_vec_int = vector[vector["int"]]

I have played around with some ideas, but it seems like I can never get to
a point where the design does not look bloated and/or brittle. Thus I am
wondering, is there anyone that tackled a problem like this before in
Boost.Python and has pointers/suggestions on how to do this properly?
Support for things like default template arguments would definitely be a
plus.

FWIW, I have access to C++11 on the C++ side, so I can deal with variadic
templates and other amenities in a not-so-kludgy way.

Thanks for any input,

  Francesco.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20140319/cdf042ba/attachment.html>


More information about the Cplusplus-sig mailing list