Boost logo

Boost :

From: Jaakko Jarvi (jajarvi_at_[hidden])
Date: 2002-02-19 10:07:52


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);

Forward declaration is possible,
and it'd be quite a lot easier than to write something like:

vector<typeof((*(const vector<A>*)0)[0] + (*(const vector<B>*)0)[0])>

(cast 0 to const vector<A>*, dereference it and take the first element,
same for vector<B>, do the addition and take typeof)

I cannot see any major difficulties in incorporating this feature to
typeof.

/Jaakko


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