[C++-sig] pybindgen: Why do wrapped C++ containers not look more like python containers?

J. Michael Owen mikeowen at llnl.gov
Thu Jun 4 02:22:22 CEST 2009


I've been looking at pybindgen and have a simple question -- why do  
the container wrappers not implement more of the python container  
interface?  For instance, you can expose the std::vector<int> like so:

vecint = mod.add_container("std::vector<int>",         "int",     
"vector", custom_name="vector_of_int")

The resulting type won't let you take the length with "len" or index  
into the instances with [].  I would naively think maybe I could add  
these methods as appropriate to types using "add_method" like the  
following:

vecint.add_method("size", "int", [], custom_name = "__len__")

but because "Container" does not inherit from "CppClass" I don't see  
how to easily extend the container in this manner.  Is there a deep  
reason these things are this way?

Thanks!

Mike.




More information about the Cplusplus-sig mailing list