Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2002-02-21 10:17:25


From: "Herb Sutter" <hsutter_at_[hidden]>
> > From: "Herb Sutter" <hsutter_at_[hidden]>
> > > Thanks for all the replies. I'm digesting them.
> > >
> > > What are the exact semantics of auto?
> >
> > auto x = expr;
> > // do something with x
> >
> > is equivalent to
> >
> > template<class X> void do_something_with_x(X x);
> > do_something_with_x(expr);
>
> Sounds good to me.
>
> New question: It seems that strict typeof would give the same result as
the
> above.

Not if 'expr' is const, or is a reference:

int & expr();

auto x = expr();

We want

int x = expr();

and not

int & x = expr();

that will leave us with a dangling reference.

In contrast, I want typeof() to leave the reference intact so I can write

typeof(expr()) f()
{
    return expr();
}

and retain the exact return type. (It is possible to strip a reference with
type traits if strictness isn't needed.)


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