The semantics of the two are completely different. initializer_list has pointer semantics, and vector value semantics.
In the first example, the compiler will generate code similar to the following:
int const __temp_array[3] = {1, 2, 3}; cout << sumL(std::initializer_list<int>(__temp_array, __temp_array + 3)) << "\n";
This is explained in [dcl.init.list] / 5. As you can see, in sumL you have access to const pointers to the elements of the braced-init-list, this means that you have no other option but to copy the elements from the list.
In the case of sumV you could std::moved use elements from vector if necessary (provided that the parameter type is not const ).
Similarly, copying initializer_list makes small copies, i.e. only pointers will be copied, and copying vector , of course, means that the elements will be copied.
In your example, none of the above items matters, except for creating a vector dynamic memory allocation will be required, and there will be no initializer_list when building.
Praetorian
source share