Reputation: 2193
I'm implementing a collection of intrusive containers trying to be Standard Library like as possible. I'm considering whether I should support std::initializer_list
but I don't quite grasp its semantics.
Basically if I had this code:
std::string a = "a";
std::string b = "b";
std::string c = "c";
std::initializer_list<std::string> list = { a, b, c };
// pass list to a container or whatever
Are the objects passed from the initializer list actual copies or "references" to the strings a
, b
and c
?
Upvotes: 2
Views: 100
Reputation: 409166
From this std::initializer_list
reference:
An object of type
std::initializer_list<T>
is a lightweight proxy object that provides access to an array of objects of typeconst T
.
What that means is that objects in the initializer list is stored by value. So to answer your question, yes copies will be made.
Upvotes: 4