Boost logo

Boost :

From: Marco Costalba (mcostalba_at_[hidden])
Date: 2007-11-03 03:04:40


On 11/3/07, Joel de Guzman <joel_at_[hidden]> wrote:
> >
> > I would say it's impossible in C++ ;-)
> >
>
> Actually it is possible in c++. You push the overload resolution at
> runtime. It will never be as efficient though. With this implementation,
> you use the C++ compiler to select the correct overload for you.
> Very fast. Without a constrained list of signatures, the compiler
> cannot be used to do the selection. You are on your own. You have
> to perform the overload resolution by mimicking the way overload
> resolution takes place in C++ in your code at runtime.
>

The problem I see is not the overload resolution that is some way you
_could_ resolve at runtime using dynamic polymorphism, i.e deriving
all the functions objects wrappers from a base class and store a new
pointer to base class for each function registered with set().

The problem is the calling of the registered functions with the
correct number and types of arguments. For that you cannot rely on a
common base class.

In the fist version of my little object factory I use an involved
matching algorithm to overcome this. I tried, given the argument list
to use at calling time, to find a stored function with the _same_
argument types (note not compatible, because implicit conversions does
not work in this case). The matching was based on dyamic_cast (one
could think also of typeid). It works but the result is suboptimal: no
implicit conversions, no compile time errors for unmatching arguments,
still difficult to handle all the const-volatile-reference
combinations.

The last version, the one now in Vault, uses pre-registartion of
signatures at compile time: it's far more easier and efficient and
powerful (implicit conversions do work).

Marco


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk