summaryrefslogtreecommitdiffstats
path: root/src/corelib/doc
diff options
context:
space:
mode:
authorKai Koehne <kai.koehne@theqtcompany.com>2015-06-26 16:57:32 +0200
committerKai Koehne <kai.koehne@theqtcompany.com>2015-07-01 12:13:28 +0000
commit04b9f865619770770899ba228b7b6503d990e2f1 (patch)
tree5ee6dfc11ecfaa28843972642463219584a953f6 /src/corelib/doc
parent5a3fe3e97aa6cae4c5db54b7b2958b82a94310c4 (diff)
Doc: Give advice on foreach vs range-based for
Task-number: QTBUG-41636 Change-Id: I28c1424e7f4c1c4da596bcae66283b60f471a8ee Reviewed-by: Martin Smith <martin.smith@digia.com>
Diffstat (limited to 'src/corelib/doc')
-rw-r--r--src/corelib/doc/src/containers.qdoc7
1 files changed, 7 insertions, 0 deletions
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: