April 24th, 2006

  • evan

(possibly dumb) c++ question

In the pattern
for (foo::iterator i = bar.begin(); i != bar.end(); ++i) ...
Does bar.end() return a new end iterator on each run through the loop? If so, isn't that inefficient (running a constructor, returning an object via the stack, etc.)?

Update: thanks everyone! The one-sentence answer is "yes, it returns via the stack, but no, it's often just a pointer so it's not inefficient".