Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2002-02-22 08:20:32


From: "Herb Sutter" <hsutter_at_[hidden]>
> > The exact semantics of the auto declaration depend on its intended use.
>
> Could you amplify on that sentence?

Only that "auto" is overloaded and different people have different ideas on
what 'auto' means. It ain't going to be easy.

My idea of auto is what I described in the previous post, a convenient
shorthand that avoids defining a helper function template.

Real-world example of its intended use:

tracking_reader tr(u, boost::bind(win32::setWindowText, hDlgLoading,
boost::bind(mbytes, _1)), 1048576);

I'd like to rephrase that as

auto mbytes = boost::bind(mbytes, _1));
auto callback = boost::bind(win32::setWindowText, hDlgLoading, mbytes);

tracking_reader tr(u, callback, 1048576);

It's a bit clearer. :-)

> > In the common case where auto declarations are used to introduce named
> > temporaries [...] we don't need the temporary to be a reference, or be
> > const.
>
> So does the first sentence mean the semantics of auto should depend on
whether
> it's an automatic variable declaration (for any reason, not just named
> temporaries) vs. a return type?

Yes. My own opinion is that we don't need auto return types. This goes
somewhat against the spirit of C++ where declarations are sufficient and
function bodies do not affect the behavior of the caller.

I think that given typeof, there is no need to autodeduce the return type.
True, it makes declarations a bit cumbersome (since the typeof-based return
type inference sometimes duplicates the function body) but it's nowhere near
the current status quo and creates much less problems language-wise.

The remainder of your post should be addressed by a proponent of auto return
types. :-)


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