J
James Kanze
Interesting. Compiled with gcc, the code terminates with the 'expected'
output. With Sun CC, it loops forever.
The problem is probably how foo.end() is calculated.
Or how it is used inside insert. I can imagine that some
implementations first create the list to be inserted, then
splice it in (which gives "123123"), others insert one element
at a time (which results in an infinite loop if the end iterator
actually points to a "virtual" element guaranteed to be at the
end---a frequent implementation).
An implementation is free to use either, since it can assume
that the second and third iterators are not iterators into foo
(because this is a precondition for insert).
Just curious: but what would you "expect" as the behavior if the
first iterator were foo.begin() + 1 (i.e. into the middle of the
list being inserted)?