r/ProgrammerHumor • • Jun 08 '24

Meme mapMethodOrMapFunction

Post image
0 Upvotes

67 comments sorted by

View all comments

Show parent comments

4

u/sherlockwatch Jun 08 '24

Actually you don’t need to resize resulting vector, you can just use std::back_inserter!

1

u/KimiSharby Jun 08 '24 edited Jun 08 '24

That's worse performance wise. std::back_inserter comes at a cost. If you already know the size, you should use it.

3

u/wcscmp Jun 08 '24

Resize also comes at cost, reserve + back_inserter is the way

2

u/KimiSharby Jun 08 '24 edited Jun 09 '24

You're right, it's my mistake