class template
<initializer_list>

std::initializer_list

template<class T> class initializer_list;
Initializer list
This type is used to access the values in a C++ initialization list, which is a list of elements of type const T.

Objects of this type are automatically constructed by the compiler from initialization list declarations, which is a list of comma-separated elements enclosed in braces:
 
auto il = { 10, 20, 30 };  // the type of il is an initializer_list 


Notice though that this template class is not implicitly defined and the header <initializer_list> shall be included to access it, even if the type is used implicitly.

initializer_list objects are automatically constructed as if an array of elements of type T was allocated, with each of the elements in the list being copy-initialized to its corresponding element in the array, using any necessary non-narrowing implicit conversions.

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 (reference semantics).

The lifetime of this temporary array is the same as the initializer_list object.

Constructors taking only one argument of this type are a special kind of constructor, called initializer-list constructor. Initializer-list constructors take precedence over other constructors when the initializer-list constructor syntax is used:
1
2
3
4
5
6
7
8
struct myclass {
  myclass (int,int);
  myclass (initializer_list<int>);
  /* definitions ... */
};

myclass foo {10,20};  // calls initializer_list ctor
myclass bar (10,20);  // calls first constructor 




Template parameters

T
Type of the elements.
Aliased as member type initializer_list::value_type.

Member types

member typedefinition
value_typeThe template parameter (T)
referenceconst T&
const_referenceconst T&
size_typesize_t
iteratorconst T*
const_iteratorconst T*

Member functions


Non-member function overloads

  • <nobr id="pwjBlLZ"><bdo id="pwjBlLZ"></bdo></nobr>
  • <bdo id="pwjBlLZ"><delect id="pwjBlLZ"></delect></bdo>
  • <bdo id="pwjBlLZ"><delect id="pwjBlLZ"></delect></bdo>
  • <dfn id="pwjBlLZ"></dfn>
  • <dfn id="pwjBlLZ"><delect id="pwjBlLZ"></delect></dfn>
  • <bdo id="pwjBlLZ"></bdo>
  • <bdo id="pwjBlLZ"><delect id="pwjBlLZ"></delect></bdo><dfn id="pwjBlLZ"><delect id="pwjBlLZ"><strike id="pwjBlLZ"></strike></delect></dfn><bdo id="pwjBlLZ"></bdo>
  • <bdo id="pwjBlLZ"></bdo><dfn id="pwjBlLZ"></dfn>
  • <dfn id="pwjBlLZ"></dfn>
  • <dfn id="pwjBlLZ"><delect id="pwjBlLZ"></delect></dfn>
  • <bdo id="pwjBlLZ"></bdo>
  • <dfn id="pwjBlLZ"></dfn>
  • <bdo id="pwjBlLZ"><delect id="pwjBlLZ"></delect></bdo>
  • 6478461606 2018-02-24
  • 4985791605 2018-02-24
  • 5637141604 2018-02-24
  • 282181603 2018-02-24
  • 6217941602 2018-02-24
  • 5076141601 2018-02-24
  • 714281600 2018-02-24
  • 6607141599 2018-02-24
  • 949041598 2018-02-24
  • 6809961597 2018-02-24
  • 671871596 2018-02-24
  • 7107821595 2018-02-24
  • 9407391594 2018-02-24
  • 6234261593 2018-02-24
  • 1793521592 2018-02-23
  • 2864591591 2018-02-23
  • 6167231590 2018-02-23
  • 3669201589 2018-02-23
  • 7946381588 2018-02-23
  • 8957701587 2018-02-23