On Monday 07 December 2015 14:41:00 Knoll Lars wrote: > On 07/12/15 15:44, "Development on behalf of Marc Mutz" <development- [email protected] on behalf of [email protected]> wrote: > >On Monday 07 December 2015 13:48:58 Ziller Eike wrote: > >> I do not think that more usage of ‘auto’ will make any code (or > >> refactorings of it) ‘safer’. IMO this is only about convenience and > >> readability. > >> > > std::map<std::string, std::string> stdMap = ...; > > > > for (const std::pair<std::string, std::string> &e : stdMap) > > > > doSomething(e.first, e.second); > > > > for (const auto &e : stdMap) > > > > doSomething(e.first, e.second); > > > >The second loop is at least two orders of magnitude faster (doSomething() > >is an out-of-line no-op). > > I think the summary here is that auto gives you one guarantee: It won’t do > an implicit conversion for the initial assignment.
Correct. The first line is missing the const in the pair's first type, thus forces an implicit conversion to the declared type (the const-& conveniently extending the lifetime of the temporary so everything appears to work, execept you're deep-copying two std::strings now). -- Marc Mutz <[email protected]> | Senior Software Engineer KDAB (Deutschland) GmbH & Co.KG, a KDAB Group Company Tel: +49-30-521325470 KDAB - The Qt Experts _______________________________________________ Development mailing list [email protected] http://lists.qt-project.org/mailman/listinfo/development
