Since C++11, range based loops are available for iterating over a known range of values. For example, when there is a need to process elements of a container, range based loops are usually a good choice. They are easy to write, read and understand. This EasyHack is about using range based loops when it is more appropriate. This is an example where range based loop was better suited: Use range based for loops https://git.libreoffice.org/core/+/47728bb925b33a8fe536fed8c913a2669bf101b6 Make sure that you understand where to use reference or const reference if needed. A suggested reading: https://blog.knatten.org/2013/10/13/prefer-using-references-with-range-based-for-loops/
Henrik Palomäki committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/6f435016092953478b5636fe9078866500fc7b90 tdf#145538 Use range based for loops It will be available in 7.3.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
Harjot committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/34a0f7023aad59bc054385f0593606d5d602e052 tdf#145538 Use range based for loops in EnhancedShapeDumper.cxx It will be available in 7.3.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
Ramreiso Kashung committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/7886b6a56a51cb699fb2a18d8a8dff0e224bdfb5 tdf#145538 : Using range-based for loops It will be available in 7.4.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
Ankur Khandelwal committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/96882cdec23c64974737c4833f157d54b85a129e tdf#145538 Use range based loops It will be available in 7.4.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
dtm committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/582bf1a27c5adc6684e8d9af3805cfe40fa051d5 tdf#145538 - Use range based for loops It will be available in 7.4.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
VaibhavMalik4187 committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/e7b01e4a5a856543e85f614c82950122e9598518 tdf#145538 - Use range based for loops It will be available in 7.4.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
Deep17 committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/f63a6f2e396fa41ed1338dcec874e06159cafa9f tdf#145538 - Use range based for loops It will be available in 7.4.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
Re-evaluating the EasyHack in 2022 This issue is still relevant, as there are many places in the code that range based for loops can be used.
Stanislav Lopatin committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/815851d1cbc427bbd85da1638f3b121b253d0926 tdf#145538 Change common loops to range based in ScanlineToolsTest.cxx It will be available in 7.5.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
PoonamShokeen committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/08a63a88543b0da68380090b655e777bd2b980be tdf#145538 Use range based for loops It will be available in 7.5.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
Stanislav Lopatin committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/91f91815124c00727eefdd92fbed2d927faaf60b tdf#145538 Change common loops to range based. It will be available in 7.5.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
Andrea Rosetti committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/e005259a6d4e237411c1b4adfb1b63313bcc5980 tdf#145538 use range based for loops It will be available in 7.5.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
OmkarAcharekar committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/7b63242ea72885d05faa5f0879395fa93a3446d1 tdf#145538 - Use range based for loops It will be available in 7.5.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
jsala committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/64469bb1a7383da6e7ff1150d693b3e08f54bc91 tdf#145538 Use range based for loops It will be available in 7.5.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
Hossein committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/acf7a851e87ec993ae828ccbf1bfb25448e88423 Revert "tdf#145538 Use range based for loops" It will be available in 7.5.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
Leonid Ryzhov committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/ed9eef72e0f616b9c626629c4233b725ca5506ce tdf#145538 Use range based for loops It will be available in 7.6.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
mostafa-elsharnoby committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/5d2be45a788c450e6f914eea8c3b74d214edaccd tdf#145538 Use range based for loops It will be available in 7.6.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
gokulakrishnan-shankar committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/20a5e38ee279022b7e6fbc32d2d259738244c0fd tdf#145538 Refactor to use range-based for-loops It will be available in 7.6.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
anfanite396 committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/34f7c8cce9c16861940f403f9a633fe8b26ba4ad tdf#145538 Use range based for loops It will be available in 7.6.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
ektagoel12 committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/87f52dbf4faf8dcd6fcc1b070e070b9ca8584ac4 tdf#145538 Use range based for loops It will be available in 7.6.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
Radhey Parekh committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/f43c365fdddfaa6095c5392e3044914ad1054652 tdf#145538 Use range based for loops It will be available in 7.6.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
Supriyo Paul committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/e08c910f9ee520ce00fe99d6dab9988138996ee3 tdf#145538: traditional for loops to range-based for loops It will be available in 7.6.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
Dr. David Alan Gilbert committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/4998370216bbea3bcaff7fac2d62cbb4ac978c5d tdf#145538,tdf#147021: sw/source: range based loops It will be available in 7.6.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
Dr. David Alan Gilbert committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/7bec1689fcbe9102aa220739b6113118d9a8dd1f tdf#145538,tdf#147021: qa: range based loops It will be available in 7.6.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
buldi committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/aff52ed56af99c4f1fcf20efd6303d7653f39233 tdf#145538 Refactor to use range-based for-loop It will be available in 24.2.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
buldi committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/65a20a85c20ddc87d66445657404a46041bcf6e1 tdf#145538 Refactor to use range-based for-loop It will be available in 24.2.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
Adam Seskunas committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/046cee10e62993238534c68e33d97ed63067b290 tdf#145538 Change traditional for loop to range based for loop It will be available in 24.2.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
Yli875 committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/67594344631c362d43b9d6a0cfadefbcfa5046d8 tdf#145538 Use range based for loops in idl:object It will be available in 24.2.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
Note: don't apply this task to odk/examples. They conform to the SDK C++ baseline, which is still C++98. (Thanks, Stephan Bergmann)
Luv Sharma committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/54f2bd45346c0e4a6331ddce5c23aec0c37b0dba tdf#145538 Use range based for loops It will be available in 24.8.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
Kira Tubo committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/ba8f4bff6015013013df652efbfaf4d9ae10c881 tdf#145538 Use range based for loops It will be available in 24.8.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
achintya committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/eec344c49f13cc0a0a3ae9e4b98a842ec39ee446 tdf#145538 use std::equal in place of for loop It will be available in 24.8.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
should I do something this in this libreoffice/basic/source/classes/image.cxx file at line 429- for( size_t i = 0; i < mvStringOffsets.size(); i++ ) { sal_uInt16 nOff = static_cast<sal_uInt16>(mvStringOffsets[ i ]); OString aStr(OUStringToOString(std::u16string_view(pStrings.get() + nOff), eCharSet)); memcpy( pByteStrings.get() + nOff, aStr.getStr(), (aStr.getLength() + 1) * sizeof( char ) ); } to something like - for (const sal_uInt32& offset : mvStringOffsets) { sal_uInt16 nOff = static_cast<sal_uInt16>(offset); OString aStr(OUStringToOString(std::u16string_view(pStrings.get() + nOff), eCharSet)); memcpy(pByteStrings.get() + nOff, aStr.getStr(), (aStr.getLength() + 1) * sizeof(char)); }
(In reply to Devansh Varshney from comment #33) > should I do something this in this > libreoffice/basic/source/classes/image.cxx file at line 429- > > for( size_t i = 0; i < mvStringOffsets.size(); i++ ) > { > sal_uInt16 nOff = static_cast<sal_uInt16>(mvStringOffsets[ i ]); > OString > aStr(OUStringToOString(std::u16string_view(pStrings.get() + nOff), > eCharSet)); > memcpy( pByteStrings.get() + nOff, aStr.getStr(), > (aStr.getLength() + 1) * sizeof( char ) ); > } > > to something like - > > for (const sal_uInt32& offset : mvStringOffsets) { > sal_uInt16 nOff = static_cast<sal_uInt16>(offset); > OString aStr(OUStringToOString(std::u16string_view(pStrings.get() + > nOff), eCharSet)); > memcpy(pByteStrings.get() + nOff, aStr.getStr(), (aStr.getLength() + 1) > * sizeof(char)); > } Please discuss such in a Gerrit patch you send. It is usually the best place.
Keldin Maldonado (KNM) committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/5dadcd1ea9e63bcbc0a5d4c4cd95d7d8b37edef9 tdf#145538 use range based for loops It will be available in 24.8.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
AhmedHamed committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/9786fb8b94889072c2f5b3a7d4724d9bab6c3261 tdf#145538 Use range based for loops It will be available in 24.8.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
RMZeroFour committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/03c9875b873d24d72587ab7d9f3190c7c0cf0e5e tdf#145538 Use range based for loops It will be available in 24.8.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
This is a task multiple people can work on at the same time, let's leave it unassigned.
Tip from https://dev.blog.documentfoundation.org/2022/03/08/use-range-based-for-loops-easyhack/ You can find some possible candidates for changing to range based for loops with these commands: git grep -w for *.cxx | grep -iF "size()" git grep -w for *.cxx | grep -iF "length()"
U-AMANDAQUARESMA\quare committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/fc3e2c8bba202a3ea3e92672f566d6ec16f18681 tdf#145538 Use range based for loops It will be available in 24.8.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
Yuki Joou committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/cfe6ce1656754776568be5b30217efc08aa70dc0 tdf#145538 - related: Make tools::PolyPolygon iterable It will be available in 25.2.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
Zainab Abbasi committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/2b25d81905684bff16a37972c7c6de26ce8447f6 tdf#145538 Use range based for loops It will be available in 25.2.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
Sohrab Kazak committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/b28fdc6b412c30b2d16c622483be4e6ee1359121 tdf#145538 tdf#153109 Use all_of / range-based for loops It will be available in 25.2.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
Adesola Samuel committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/3b8d833dba336e3baf3552e89aeb2695dad41960 tdf#145538 Range based for loop cannot be used in SfxBroadcaster.cxx It will be available in 25.2.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
Adesola Samuel committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/9b2c470c317fcf3cb248c4fffbbe21f4311205b2 tdf#145538 Use range based for loop in textsh1.cxx It will be available in 25.2.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
You can find some of the possible candidates with this grep command which uses regular expressions: $ git grep -E "for ?\("|grep -iE "size\(\)|length\(\)"
MelvinYG committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/e04742c0a55f0361bf9bae19c65fe21a3099e60a tdf#145538: Use range based for loops It will be available in 25.2.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.