So, according to n2243 , a range-based loop is equivalent to this:
{
auto && __range = ( expression );
for ( auto __begin = std::Range<_RangeT>::begin(__range),
__end = std::Range<_RangeT>::end(__range);
__begin != __end;
++__begin )
{
for-range-declaration = *__begin;
statement
}
}
Then he says 2 If the header <iterator_concept> is not included prior to a use of the range-based for statement, the program is ill-formed., so I ask how relevant this is. I am also curious about what std::Rangeis, or is it just an implementation detail. The closest I can find is the n3350 .
This answer builds on this information and says:
The range for operation is as fast as possible, since it caches the end of the iterator [quote], uses pre-increment and only plays the iterator once.
therefore, if you tend to write:
for(iterator i = cont.begin(); i != cont.end(); i++) { /**/ }
Then yes, the range can be a little faster, since it also write there, there is no reason not to use it (if necessary).
P.S. , . , .
, . , . , , auto it = s.rbegin(); it != s.rend(); ++it, , , , , begin end. , , , , begin end? , , , - 2007 .