Boost logo

Boost :

From: David Abrahams (david.abrahams_at_[hidden])
Date: 2002-02-19 10:00:14


The reason to re-use auto is that it's "underloaded" (Andy Sawyer's term).
Nobody uses it! As long as we have to have the keyword, it might as well be
useful for something. When I first started exploring this area, I proposed
'auto' for this purpose. Later I became enamoured of Andy Koenig's idea of
using templated variable declarations (as quoted below), but people like
Emily have convinced me that it doesn't buy much, doesn't solve all the
problems we want to solve, and introduces more complexity than neccessary.

-Dave

----- Original Message -----
From: "brianjparker" <brianjparker_at_[hidden]>

> My major objection to the "auto" proposal is its syntax- I think that
> one can achieve the same result as a pure extension without
> overloading a keyword (or introducing a new keyword) by simply
> extending to function return and local variables the existing type
> deduction rules applied to function arguments.
> e.g. in
>
> template<typename R, typename T1, typename T2>
> R min(T1 t1, T2 t2)
> {
> if (t1 < t2) return t1;
> else return t2;
> }
>
> if R is not explicitly specified in the function call then it is
> deduced (as if it were specified with the putative "auto" keyword.)
>
> This could also be extended to local variables-
>
> template<typename T1, typename T2, typename L>
> void func(T1 t1, T2 t2)
>

> const L& l = t1 + t2;
> // ...
> }
>
> One possible disadvantage with this syntax is that it is limited to
> template functions by definition, but this in fact could be an
> advantage as it maintains the distinction between C-compatible non-
> template functions and C++ generic functions.
>
> Another possible disadvantage for the local variable deduction case
> is that if there were many deduced local variables then the function
> template argument list could become unwieldy. I don't think that this
> would be a problem in practice, but if it was then an alternative
> syntax (suggested by David Abrahams who attributed it to Andrew
> Koenig), such as-
>
> template<typename T1, typename T2>
> void func(T1 t1, T2 t2)
>

> template<typename L>
> const L& l = t1 + t2;
> // ...
> }


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