std::initializer_list (3) - Linux Manuals
std::initializer_list: std::initializer_list
NAME
std::initializer_list - std::initializer_list
Synopsis
Defined in header <initializer_list>
template< class T > (since C++11)
class initializer_list;
An object of type std::initializer_list<T> is a lightweight proxy object that provides access to an array of objects of type const T.
A std::initializer_list object is automatically constructed when:
* a braced-init-list is used to list-initialize an object, where the corresponding constructor accepts an std::initializer_list parameter
* a braced-init-list is used as the right operand of assignment or as a function_call_argument, and the corresponding assignment operator/function accepts an std::initializer_list parameter
* a braced-init-list is bound to auto, including in a ranged_for_loop
Initializer lists may be implemented as a pair of pointers or pointer and length. Copying a std::initializer_list does not copy the underlying objects.
The underlying array is not guaranteed to exist after the lifetime of the original initializer list object has ended. The storage for std::initializer_list is unspecified (i.e. it could be automatic, temporary, or static read-only memory, depending on the situation). (until C++14)
The underlying array is a temporary array of type const T[N], in which each element is copy-initialized (except that narrowing conversions are invalid) from the corresponding element of the original initializer list. The lifetime of the underlying array is the same as any other temporary_object, except that initializing an initializer_list object from the array extends the lifetime of the array exactly like binding_a_reference_to_a_temporary (with the same exceptions, such as for initializing a non-static class member). The underlying array may be allocated in read-only memory. (since C++14)
The program is ill-formed if an explicit or partial specialization of std::initializer_list is declared. (since C++17)
Member types
Member type Definition
value_type T
reference const T&
const_reference const T&
size_type std::size_t
iterator const T*
const_iterator const T*
Member functions
constructor (public member function)
Capacity
size (public member function)
Iterators
begin (public member function)
end (public member function)
Non-member functions
std::begin(std::initializer_list) specializes std::begin
(C++11)
std::end(std::initializer_list) specializes std::end
(C++11)
Defined in header <iterator>
rbegin(std::initializer_list) specializes std::rbegin
(C++14)
rend(std::initializer_list) specializes std::rend
(C++14)
Example
// Run this code