Re: General question about vectors
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 ___ LibreOffice mailing list LibreOffice@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice
Re: General question about vectors
On 01/27/2014 06:34 AM, Andrew Douglas Pitonyak wrote: 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? 3. The applied function is easy to identify (it is named). ...which cuts both ways, as you need to first look for the function's definition to see what it does exactly, compared to having it inline at the point of use (and will become more moot with C++11 lambdas). That's IMO a reason why in C++03 a for loop with a short body can be overall preferable to a for_each that requires a one-off function definition. Stephan ___ LibreOffice mailing list LibreOffice@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice
Re: General question about vectors
On Mon, Jan 27, 2014 at 11:35:22AM +1100, Chris Sherlock chris.sherloc...@gmail.com 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? It's kind of a stylistic question: http://stackoverflow.com/questions/7985687/why-use-stdfor-each-over-a-for-loop signature.asc Description: Digital signature ___ LibreOffice mailing list LibreOffice@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice