From 11f895bffff6352ef3efbe1293b84b389da8fd94 Mon Sep 17 00:00:00 2001 From: Andrey Astafyev Date: Sun, 19 Apr 2020 00:28:00 +0300 Subject: [PATCH] range-loop-add-qasconst --- src/cmlib-example/main.cpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/cmlib-example/main.cpp b/src/cmlib-example/main.cpp index 5cc645f..f016ec8 100644 --- a/src/cmlib-example/main.cpp +++ b/src/cmlib-example/main.cpp @@ -3,6 +3,18 @@ #include #include +// function args by ref +int sum(QStringList sl) +{ + int s = 0; + for(auto str: sl) + { + s += str.toInt(); + } + return s; +} + + int main( int argc, char** argv ) { QCoreApplication app( argc, argv ); @@ -17,10 +29,20 @@ int main( int argc, char** argv ) // loop add ref QStringList sl; - for (auto s: sl) + sl << "111" << "222" << "333"; + for (const auto &s: sl) { qDebug() << s; } + // loop qasconst + for (auto s: sl) + { + s.append("0"); + } + + // function args by ref + auto ir = sum(sl); + return( 0 ); }