Boost logo

Boost :

From: Herb Sutter (hsutter_at_[hidden])
Date: 2002-02-19 00:35:08


Gary wrote:
> "Auto" for type deduction.

> Yet another call for "auto" and that's for use in
> teaching:

Good points. Then:

> typeof
>
> Lambda needs to be able to deduce the type of an expression.
>
> template<class T, class S>
> WHAT_IS_THIS_TYPE? operator+(T &t, S &s)
> { return t+s; }
>
> so we need something of the order of:
>
> template<class T, class S>
> typeof(S + T) operator+(T &t, S &s)
> { return t+s; }

(Note the typo above: "typeof(S+T)" vs. "return t+s;".)

Why not use "auto" here? It would avoid the typo too:

     template<class T, class S>
     auto operator+(T &t, S &s)
       { return t+s; }

If different branches would return different things, well, we already have a
rule about that sort of type compatibility for the ?: operator.

Herb


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