From: David Abrahams (dave_at_[hidden])
Date: 2002-11-08 09:17:06
Dan Nuffer <dnuffer_at_[hidden]> writes:
> David Abrahams wrote:
>> Dan Nuffer <dnuffer_at_[hidden]> writes:
>>>2. Is is possible to wrap member functions which take a variable
>>>number of arguments (e.g. int format(const char* fmt, ...); ) ? I
>>>tried .def("format", &OW_String::format) but that doesn't work.
>> Not directly. Conversions from Python to C++ are "target-driven",
>> meaning that we need to know the type of the C++ argument in order to
>> make the conversion happen. There are ways you can write a function
>> which takes an arbitrary
>> number of Python objects in an argument tuple, and you can do the
>> dispatching yourself.
>> You could also consider supporting a fixed maximum number of
>> by wrapping something like:
>> int format_dispatch(
>> char const*fmt, object a0 = object(), object a1 =
>> object()... object aN = object())
>> // implementation details left up to you ;-)
> You probably know something I don't.
Don't count on it ;-)
> I can't think of a way to do this without having a n^m explosion of
> code, where n = number of types to support and m = number of
> arguments. Is there an good way to implement this?
I don't really know. I guess it depends on what your format function
needs to do.
Can you build an appropriate function with the raw Python/C API? If
so, I can show you how to use it with Boost.Python.
-- David Abrahams dave_at_[hidden] * http://www.boost-consulting.com Boost support, enhancements, training, and commercial distribution
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk