[C++-sig] Re: Auto-Generation and BPL v2

Brad King brad.king at kitware.com
Fri Nov 8 04:37:43 CET 2002


Ralf,

> Is there a plan for auto-generating bindings for template functions? Say
> I have a function template <typename FloatType> FloatType foo(FloatType
> const&); how would an auto-generating tool "know" what to use for
> FloatType? Sometimes I need bindings for more than one type, e.g. for
> void bar(std::vector<FloatType> const&). Another question is how to deal
> with class templates, e.g. template <typename FloatType> class
> my_container; Here one has to decide what to call the different Python
> types, e.g. my_container<float> -> my_container_float, etc. (actually, I
> settled on creating a module my_container with types float, double etc.,
> leading to e.g. f = my_container.float()).

I've been developing a tool called "CABLE" (Cable Automates Bindings for
Language Extension). Take a look at http://public.kitware.com/Cable for
more information.  It already has a Tcl wrapper implementation that
handles most of these problems.  I plan to add a wrapper generator to the
project that generates Boost.Python v2 input files.

The name specification looks like this in a CABLE configuration file:

namespace wrappers {
  typedef ::my_container<float> my_container_float;
  namespace foo {
    typedef ::foo::bar bar;
  }
}

This will create a wrapper for my_container<float> that is called
my_container_float in the generated wrappers.  It will also create a
wrapper for "foo::bar" that is called "bar" in the generated wrappers, but
in a namespace (or module) called "foo".

The above seems pretty easy for class templates, but I've had trouble
coming up with a good syntax for functions and function templates.  There
isn't really a problem when the function's template arguments can all be
deduced because the function can keep its original name, and each
instantiation becomes another overload.  The problem occurs for functions
like this:

template <typename T> void f() {}

It must be called as "f<int>()", and I'm not sure how we should go about
specifying a name for this from a configuration point of view.  It gets
even more complicated when some of the arguments are deduced, but not all:

template <typename A, typename B> void f(B) {}

This can be called as "f<int>(3.4)" or "f<int, double>(3.4)".  If we have
a set of calls:

  f<int>(char());
  f<int>(float());

should they all be called "f_int" and become overloads in python?  How
does the user specify this in the config file?  Any suggestions are
welcome.

-Brad





More information about the Cplusplus-sig mailing list