Boost logo

Boost :

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
> case.
> Here's a suggestion for a feature of typeof that could be of help in this
> respect:
> 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[0]+b[0])> 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
arbitrary lookahead.

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[0] + b[0])>;

Not much chance of this happening in C++, I'm afraid.


Boost list run by bdawes at, gregod at, cpdaniel at, john at