The type is defined in the initializer_list
header
- Similar to
vector
but not same as it. The elements in aninitializer_list
are alwaysconst
.
Operations
initializer_list<T> lst; // empty list
initializer_list<T> lst{a, b, c};
lst2(lst);
lst2 = lst; // copy or assign
lst.size();
lst.begin()
lst.end();
⚠️ Copying or assigning an initializer_list
does not copy the elements in the list. After the copy, the original and the copy share the elements. (浅复制)