C++ - <initializer_list>
C++ <initializer_list>
An initializer_list object is designed to hold an array of values. An initializer_list object is automatically constructed when:
- a braced-init-list is used to list-initialize an object, where the corresponding constructor accepts an 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 initializer_list parameter.
- a braced-init-list is bound to auto, including in a ranged for loop.
The initializer_list object refers to the elements of this array without containing them. Copying an initializer_list object produces another object referring to the same underlying elements, not to new copies of them.
Syntax
template <class T> class initializer_list;
Parameters
T |
Type of the elements stored in the initializer_list. |
Member Types
Member types | Definition |
---|---|
value_type | T (First template parameter) |
reference | const T& |
const_reference | const T& |
iterator | const T* |
const_iterator | const T* |
size_type | size_t |
C++ <initializer_list> - Member Functions
The C++ <initializer_list> has a number of member functions which are listed below:
Functions | Description |
---|---|
initializer_list() | Construct an empty initializer_list. |
begin() | Returns a pointer to the first element of the initializer_list. |
end() | Returns a pointer to the past-the-last element of the initializer_list. |
size() | Returns size of the initializer_list. |
C++ <initializer_list> - Non-member Functions
The C++ <initializer_list> has a number of non-member functions which are listed below: