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

If I'm being super pedantic, I would argue that while `string::push_back` should take amortized constant time, `string::append` has no such guarantee [1]. So it is technically possible for `my_string += "a";` (same to `string::append`) will reallocate every time. Very pedantic indeed, but I have seen some C++ implementation where `std::vector<T>` is an alias to `std::deque<T>`, so...

One thing I don't like about lemire's phrasing is that he only looks at the current, often only most available, implementations and doesn't make this point explicit for most cases.

EDIT: Thankfully he does acknowledge that in a later post [2].

[1] https://timsong-cpp.github.io/cppwp/n4861/strings#string.app...

[2] https://lemire.me/blog/2023/10/23/appending-to-an-stdstring-...




> but I have seen some C++ implementation where `std::vector<T>` is an alias to `std::deque<T>`, so

I have a hard time believing that because std::vector guarantees that the memory is contiguous.


Yeah, it wouldn't be standard-compliant, and I think it was very ancient one---at least as old as STLport I believe.




Consider applying for YC's W25 batch! Applications are open till Nov 12.

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

Search: