[Development] RFC: more liberal 'auto' rules?
Marc Mutz
marc.mutz at kdab.com
Mon Dec 7 17:50:41 CET 2015
On Thursday 03 December 2015 19:49:46 Marc Mutz wrote:
> The remainder of the C++ world is moving towards an "always auto" scheme.
> We don't need to go there, but I'd at least like to propose, for new code
> and as a drive-by, the required use of auto for:
>
> - template code (esp., but not necessarily only, when the type name would
> require the use of 'typename')
> - all loop variables (both index and iterators)
> the reason being that spelling out the name is usually wrong:
> size_t i = stdVector.size() // wrong, should be std::vector::size_type...
> also helps when porting from Qt containers to STL ones
> - all references to elements in a collection (same problem - way too easy
> to misspell std::pair<int, int> for std::pair<const int, int>...)
Let me extend that:
- whenever possible when declaring a QList
It seems like we all agree that QList as-is will not be in Qt 6[1]. To me,
it sounds prudent to anticipate that and to hold QList (whereever possible)
in auto variables only, so they port themselves automatically (no pun
intended) to, say, QVector, std::vector, or QArrayList.
[1] Before you flame again: Independant of the exit strategy, it should be
consensus that the *name* QList will only exist as a porting vehicle
(deprecated class or deprecated template alias or something entirely
different). Whether the actual implementation lives on as QArrayList (say) is
orthogonal to that.
Thanks,
Marc
--
Marc Mutz <marc.mutz at kdab.com> | Senior Software Engineer
KDAB (Deutschland) GmbH & Co.KG, a KDAB Group Company
Tel: +49-30-521325470
KDAB - The Qt Experts
More information about the Development
mailing list