Std::initializer list
lastmod 2026-11-10created 2015-06-222 edits
std::initializer_list is a lightweight template class in C++11 that lets functions and constructors receive the list of values passed with brace initialization {1, 2, 3}. The compiler creates a temporary array and an initializer_list object pointing to its range, and the elements can be read with begin(), end(), and size(). Standard containers support initialization such as std::vector<int>v = {1, 2, 3}; thanks to constructors that take this type.