From 04b9f865619770770899ba228b7b6503d990e2f1 Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Fri, 26 Jun 2015 16:57:32 +0200 Subject: Doc: Give advice on foreach vs range-based for Task-number: QTBUG-41636 Change-Id: I28c1424e7f4c1c4da596bcae66283b60f471a8ee Reviewed-by: Martin Smith --- src/corelib/doc/src/containers.qdoc | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/corelib/doc/src/containers.qdoc') diff --git a/src/corelib/doc/src/containers.qdoc b/src/corelib/doc/src/containers.qdoc index 1979c45e17..f8d0d3eb05 100644 --- a/src/corelib/doc/src/containers.qdoc +++ b/src/corelib/doc/src/containers.qdoc @@ -601,6 +601,13 @@ container. It only affects the copy, which is probably not what you want. + An alternative to Qt's \c foreach loop is the range-based \c for that is + part of C++ 11 and newer. However, keep in mind that the range-based + \c for might force a Qt container to \l{Implicit Sharing}{detach}, whereas + \c foreach would not. But using \c foreach always copies the container, + which is usually not cheap for STL containers. If in doubt, prefer + \c foreach for Qt containers, and range based \c for for STL ones. + In addition to \c foreach, Qt also provides a \c forever pseudo-keyword for infinite loops: -- cgit v1.2.3