c++ - Should one prefer STL algorithms over hand-rolled loops? -
i seem seeing more 'for' loops on iterators in questions & answers here for_each(), transform(), , like. scott meyers suggests stl algorithms preferred, or @ least did in 2001. of course, using them means moving loop body function or function object. may feel unacceptable complication, while others may feel better breaks down problem.
so... should stl algorithms preferred on hand-rolled loops?
it depends on:
- whether high-performance required
- the readability of loop
- whether algorithm complex
if loop isn't bottleneck, , algorithm simple (like for_each), current c++ standard, i'd prefer hand-rolled loop readability. (locality of logic key.)
however, c++0x/c++11 supported major compilers, i'd use stl algorithms because allow lambda expressions — , locality of logic.
Comments
Post a Comment