[C++-sig] Dissimilar Overloads

David Abrahams dave at boost-consulting.com
Wed Dec 4 20:49:46 CET 2002

"Scott A. Smith" <ssmith at magnet.fsu.edu> writes:

> Hi,
> If one has overloaded functions with dis-similar arguments,
> do they need to be wrapped separately? While I have been able
> to successfully use BOOST_PYTHON_FUNCTION_OVERLOADS and
> argument lists that are similar and/or use default values, I cannot
> figure out how to do something equally simple to get functions with
> different types of arguments exported. For example, is there something
> like the code below that can work?
> #include <boost/python/def.hpp>
> using namespace boost::python;
> int f(int x, int y, int z);
> void f(double d, complex z);
> {
>    def("f", f, args("x", "y", "z"));
>    def("f", f, args("d", "y"));

     int (&f1)(int,int,int) = f;
     def("f", f1, args("x", "y", "z"));

     void (&f2)(double,complex) = f;
     def("f", f2, args("d", "y"));

is the easiest way. There are other hacks in this particular case, but
I'd avoid them.

                       David Abrahams
   dave at boost-consulting.com * http://www.boost-consulting.com
Boost support, enhancements, training, and commercial distribution

More information about the Cplusplus-sig mailing list