On 01/26/2014 07:35 PM, Chris Sherlock wrote:
Libreoffice takes advantage of STL vectors throughout the codebase. So
just a general question: under what circumstances is it better to use
a for loop than an STL for_each loop?
Are there specific advantages to for_each over a regular loop?
I think that the primary advantage is one of readability.
1. The code is shorter and it reads easily.
2. It is clear that every element is addressed (rather than wondering if
there is a premature break or the loop constraints do not specify the
endpoints.
3. The applied function is easy to identify (it is named).
4. It may reduce or remove complicated declaration statements for the
iterators.
I have never heard anyone argue that they are more efficient in execution.
--
Andrew Pitonyak
My Macro Document: http://www.pitonyak.org/AndrewMacro.odt
Info: http://www.pitonyak.org/oo.php
Context
Privacy Policy |
Impressum (Legal Info) |
Copyright information: Unless otherwise specified, all text and images
on this website are licensed under the
Creative Commons Attribution-Share Alike 3.0 License.
This does not include the source code of LibreOffice, which is
licensed under the Mozilla Public License (
MPLv2).
"LibreOffice" and "The Document Foundation" are
registered trademarks of their corresponding registered owners or are
in actual use as trademarks in one or more countries. Their respective
logos and icons are also subject to international copyright laws. Use
thereof is explained in our
trademark policy.