18 Language support library [language.support]

18.9 Initializer lists [support.initlist]

The header <initializer_list> defines one type.

Header <initializer_list> synopsis

namespace std {
  template<class E> class initializer_list {
  public:
    typedef E value_type;
    typedef const E& reference;
    typedef const E& const_reference;
    typedef size_t size_type;

    typedef const E* iterator;
    typedef const E* const_iterator;

    initializer_list() noexcept;

    size_t size() const noexcept;      // number of elements
    const E* begin() const noexcept;   // first element
    const E* end() const noexcept;     // one past the last element
  };

  // [support.initlist.range] initializer list range access
  template<class E> const E* begin(initializer_list<E> il) noexcept;
  template<class E> const E* end(initializer_list<E> il) noexcept;
}

An object of type initializer_list<E> provides access to an array of objects of type const E. [ Note: A pair of pointers or a pointer plus a length would be obvious representations for initializer_list. initializer_list is used to implement initializer lists as specified in [dcl.init.list]. Copying an initializer list does not copy the underlying elements.  — end note ]

18.9.1 Initializer list constructors [support.initlist.cons]

initializer_list() noexcept;

Effects: constructs an empty initializer_list object.

Postcondition: size() == 0

18.9.2 Initializer list access [support.initlist.access]

const E* begin() const noexcept;

Returns: A pointer to the beginning of the array. If size() == 0 the values of begin() and end() are unspecified but they shall be identical.

const E* end() const noexcept;

Returns: begin() + size()

size_t size() const noexcept;

Returns: The number of elements in the array.

Complexity: constant time.

18.9.3 Initializer list range access [support.initlist.range]

template<class E> const E* begin(initializer_list<E> il) noexcept;

Returns: il.begin().

template<class E> const E* end(initializer_list<E> il) noexcept;

Returns: il.end().