From: Douglas Gregor (gregod_at_[hidden])
Date: 2002-02-19 10:27:31
On Tuesday 19 February 2002 10:07 am, you wrote:
> Getting back to typeof from auto.
> Previous postings claim that typeof doesn't help much, as the
> return type expressions would be complicated and hard to write/read in any
> Here's a suggestion for a feature of typeof that could be of help in this
> Extend the scope of the function parameters to the return type expression,
> and allow them to be used inside a typeof (and sizeof) expression there.
> For example:
> template<class A, class B>
> vector<typeof(a+b)> sum(const vector<A>& a, const vector<B>& b);
From the parsing standpoint, this is bad. It requires arbitrary lookahead to
determine that a and b in the typeof expression are bound to the declarations
of a and b that follow, and most parsing styles don't deal well with
This is a good case for having the return type follow the parameter list,
template<class A, class B>
sum(const vector<A>& a, const vector<B>& b) : vector<typeof(a + b)>;
Not much chance of this happening in C++, I'm afraid.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk