Could the assign function for containers possibly overflow?

Posted by Kristo on Stack Overflow See other posts from Stack Overflow or by Kristo
Published on 2010-03-29T15:21:14Z Indexed on 2010/03/29 15:23 UTC
Read the original article Hit count: 372

Filed under:
|
|

I ran into this question today and thought I should post it for the community's reference and/or opinions.

The standard C++ containers vector, deque, list, and string provide an assign member function. There are two versions; I'm primarily interested in the one accepting an iterator range. The Josuttis book is a little ambiguous with its description. From p. 237...

Assigns all elements of the range [beg,end); this is, is replaces all existing elements with copies of the elements of [beg,end).

It doesn't say what happens if the size of the assignee container is different from the range being assigned. Does it truncate? Does it automagically expand? Is it undefined behavior?

© Stack Overflow or respective owner

Related posts about c++

Related posts about containers