diff options
author | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2016-11-09 17:37:52 +0100 |
---|---|---|
committer | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2016-12-10 18:11:38 +0000 |
commit | e5e26294f237d972122dd9d757956a8d7eea0294 (patch) | |
tree | e5e89f6dcb748b8909c5b2bd8f5369b898f9c6d7 /tests | |
parent | 4aebbef8ab94723d59679f30005b114197c995b9 (diff) |
foreach: do not use operators that trigger non-evaluated contexts
Namely: decltype(). Ideally we'd want C++17's template constructor
argument deduction, but instead use the C++11 solution: a factory
function. This enables using things such as lambdas in the container
argument.
Change-Id: Idba64d8069d15bbafe54cfdebe24b1fba1eb8d0a
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/corelib/global/qglobal/tst_qglobal.cpp | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/tests/auto/corelib/global/qglobal/tst_qglobal.cpp b/tests/auto/corelib/global/qglobal/tst_qglobal.cpp index bb6ec1c8e7..083526fdc4 100644 --- a/tests/auto/corelib/global/qglobal/tst_qglobal.cpp +++ b/tests/auto/corelib/global/qglobal/tst_qglobal.cpp @@ -102,6 +102,13 @@ void tst_QGlobal::for_each() QCOMPARE(i, counter++); } QCOMPARE(counter, list.count()); + + // check whether we can use a lambda + counter = 0; + foreach (int i, [&](){ return list; }()) { + QCOMPARE(i, counter++); + } + QCOMPARE(counter, list.count()); } void tst_QGlobal::qassert() |