Defined in: <initializer_list>
Overview
template< class T >
class initializer_list;
std::initializer_list is a light container that holds objects from list initialization or braced initialization.
Memory
This section requires improvement. You can help by editing this doc page.
Technical details
Feature testing macros
This section requires improvement. You can help by editing this doc page.
Technical definition
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<T> 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<T>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<T>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 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.
The program is ill-formed
if an explicit or partial specialization ofstd::initializer_list is declared.std::initializer_list
| Defined in | initializer_list |
Template parameters
| pub | T | Type of the elements. |
Type names
| pub | value_type | T |
| pub | reference | const T& |
| pub | const_reference | const T& |
| pub | size_type | Unsigned integer type (usually std::size_t) |
| pub | iterator | const T* |
| pub | const_iterator | const T* |
Member functions
| pub | (constructors) | Constructs a initializer list. |
| pub | (destructor) | Destroys the initializer list. |
Capacity
| pub | size | Returns the number of elements. |
Iterators
| pub | begin cbegin (od C++11) | Returns an |
| pub | end cend (od C++11) | Returns an |
Non-member functions
| pub | std::begin (std::initializer_list) | An overload for a std::begin. |
| pub | std::end (std::initializer_list) | An overload for a std::end. |
Free function templates overloaded for std::initializer_list
| pub | rbegin crbegin (od C++14) | Returns a reverse |
| pub | rend crend (od C++14) | Returns a reverse |
| pub | empty (od C++17) | Returns |
| pub | data (od C++17) | Returns a pointer to the first element of the underlying array. |
Examples
This section requires improvement. You can help by editing this doc page.
Hover to see the original license.