
3 Jan
2008
3 Jan
'08
5:35 p.m.
Neal Becker wrote:
The common idiom is:
for (; i != boost::end (vector); ++i) ...
The compiler had damn well better realize that boost::end is a constant function that can be lifted from the loop, or performance can be severely impacted.
boost::end is not a constant function, because the vector can change. However, boost::end(vector) is the same as vector._M_begin + vector._M_size (implementation specific names) I wouldn't say one addition can severely impact performance. I believe a lot of optimizers can optimize out that addition if the vector wasn't changed anyway.