While trying to understand Rvalue references from here, I am unable to understand two things
- If there are N strings in the vector, each copy could require as
many as N+1 memory allocations and
[…]
What is this +1 in ‘N+1’?
2.How the author suddenly arrives at the below guideline
Guideline: Don’t copy your function
arguments. Instead, pass them by value
and let the compiler do the copying.
Am I missing something?
One allocation to create the underlying array for the new vector, then N allocations, one for each of the N strings in the vector.
He is arguing that instead of explicitly making the copy inside of the function,
you should let the compiler make the copy when you pass the arguments to the function,