Skip to content
Snippets Groups Projects
Commit 87f320e1 authored by hjk's avatar hjk
Browse files

mention foreach (...)

parent b11f8492
No related branches found
No related tags found
No related merge requests found
...@@ -108,6 +108,34 @@ in C++. ...@@ -108,6 +108,34 @@ in C++.
\endcode \endcode
\o Using Qt's foreach is ok in non-time critical code when using a QTL
container. It is a nice way to keep line noise down and to give the
loop variable a proper name:
\code
foreach (QWidget *widget, container)
doSomething(widget);
-VS-
Container::iterator end = container.end();
for (Container::iterator it = container.begin(); it != end; ++it)
doSomething(*it);
\endcode
If the loop variable can be made const, do so. This can prevent
unnecessary detaching of shared data in some cases. So:
\code
foreach (const QString &name, someListOfNames)
doSomething(name);
- NOT -
foreach (QString name, someListOfNames)
doSomething(name);
\endcode
\section1 Formatting \section1 Formatting
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment