quick std::vector.assign question

Started by
1 comment, last by yckx 13 years, 8 months ago
Should I call std::vector::reserve() before std::vector.assign() on a new vector, or does std::vector::assign() also request storage space before assignment?
Advertisement
It depends on what kind of iterators you feed it. If you feed assign() input iterators it'll add elements one at a time. With random access iterators it should know how much it'll be adding and allocate up front.
Thanks!

This topic is closed to new replies.

Advertisement