|clazy range loop||0.73||0.3||8749||23|
Range based for loop and std::for_each () functions are among those. They are new techniques for iterating through the elements of a sequence container, like vector, arrays or strings. Before C++ 11 we used normal for loop or while loop to access the elements of a collection in a container or array.What is range based for loop and for_each() in C++11?
Range based for loop and std::for_each () function in C++11 are fulfilling that need in different situation. These features are tightly coupled with collection type object and mostly used with STL sequential containers, though can be used for user defined class meeting the requirement to be sequential container.What is the difference between normal loop and range based for loop?
Normal loop and range based loop has it’s own utility. Normal loop is a general purpose loop but range based for loop and std::for_each () function is meant for specific looping scenario. Ultimately they all work like a normal loop internally, hence performance is same.When to use 2nd version in range based loop?
Reading some examples of range based loops they suggest two main ways 1, 2, 3, 4 Well. When we don't need changing vec items, IMO, Examples suggest to use second version (by value). Why they don't suggest something which const references (At least I have not found any direct suggestion): Isn't it better?