Hacker News new | past | comments | ask | show | jobs | submit login

> For std::vector it apparently just didn't occur to C++ people to provide the correct API, Bjarne Stroustrup claims the only reason to use a reservation API is to prevent reference and iterator invalidation. -shrug-

Do you mean something like vector::reserve_at_least()? I suppose that, if you don’t care about performance, you might not need it.

FWIW, I find myself mostly using reserve in cases where I know what I intend to append and when I will be done appending to that vector forever afterwards.






I'm not familiar with vector::reserve_at_least but assuming that's an API which reserves capacity without destroying the amortized constant time of the exponential growth built in to the type, yes, that.

Oh, sorry, that’s an API that doesn’t exist. I was trying to understand what feature you wanted that didn’t exist.



Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: