First part:
std::initializer_list is a really useful C ++ 11 function, so I wondered how it is implemented in the standard library. From what I read here , the compiler creates an array of type T and gives a pointer to initializer_list<T> .
It also states that copying initializer_list will create a new object that references the same data: why is this so? I would guess that this is either:
- copies data for new
initializer_list - transfers ownership of data to a new
initializer_list
The second part of:
From one of the many online links for std::vector constructors:
vector (initializer_list<value_type> il, const allocator_type& alloc = allocator_type());
(6) initializer list constructor
Creates a container with a copy of each of the elements in il in the same order.
I don't like move semantics yet, but il data can't be transferred to vector ? I don't know about the deep implementation of std::vector , but IIRC uses plain old arrays.
source share