Boost logo

Boost :

From: Darin Adler (darin_at_[hidden])
Date: 2001-09-19 01:16:47


on 9/18/01 5:11 PM, Douglas Gregor at gregod_at_[hidden] wrote:

> But this requires partial ordering of function templates when a function
> pointer is passed in, which breaks on a _lot_ of compilers.

Your response inspired me to study the C++ standard section on partial
ordering of function templates. My testing indicates that partial ordering
of function templates works perfectly in the Metrowerks compiler even in
cases where a function pointer is passed in. But your suggested fix for the
function constructor won't work. Here's why:

    template<typename F> function(const F& f);
    template<typename OR> function(OR (*f)());

According to the rules in the standard (14.5.5.2), neither of these function
templates is at least as specialized as the other! So there's an ambiguity.
The rule is that you perform argument deduction on each of the templates,
using parameters constructed by substituting unique types for each of the
template parameters of the other. Trying to pass the function pointer type
into the "const F&" results in a deduction that succeeds, but the deduced
parameter type is not an exact match. The function pointer has to be
implicitly converted into a const reference to a function pointer, which is
not allowed (14.5.5.2p4).

(I wish I had figured this out before I sent an erroneous bug report to
Metrowerks.)

> I think you might be stuck with the extra '&' for a while longer :(

I can live with it. But I think it merits a mention somewhere in the
documentation.

    -- Darin


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