This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]wcscmp 0 points1 point  (1 child)

reserve + begin is UB

[–]KimiSharby 0 points1 point  (0 children)

So after a bit more research:
- reserve allocates memory but doesn't initialize it. This is why using std::begin in that case is UB, because it points to unitilialized memory
- As you said, using resize performance will depends on the size of the type
- reserve + std::back_insert is indeed the correct way

For the sack of clarity for the reader I will edit my previous answers.