129 lines
4.8 KiB
Markdown
129 lines
4.8 KiB
Markdown
[support.initlist]
|
||
|
||
# 17 Language support library [[support]](./#support)
|
||
|
||
## 17.11 Initializer lists [support.initlist]
|
||
|
||
### [17.11.1](#general) General [[support.initlist.general]](support.initlist.general)
|
||
|
||
[1](#general-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L4649)
|
||
|
||
The header <initializer_list> defines a class template and several
|
||
support functions related to list-initialization (see [[dcl.init.list]](dcl.init.list "9.5.5 List-initialization"))[.](#general-1.sentence-1)
|
||
|
||
All functions specified in [support.initlist] are signal-safe ([[support.signal]](support.signal "17.14.5 Signal handlers"))[.](#general-1.sentence-2)
|
||
|
||
### [17.11.2](#initializer.list.syn) Header <initializer_list> synopsis [[initializer.list.syn]](initializer.list.syn)
|
||
|
||
// all freestandingnamespace std {template<class E> class initializer_list {public:using value_type = E; using reference = const E&; using const_reference = const E&; using size_type = size_t; using iterator = const E*; using const_iterator = const E*; constexpr initializer_list() noexcept; constexpr size_t size() const noexcept; // number of elementsconstexpr const E* begin() const noexcept; // first elementconstexpr const E* end() const noexcept; // one past the last element}; // [[support.initlist.range]](#range "17.11.5 Initializer list range access"), initializer list range accesstemplate<class E> constexpr const E* begin(initializer_list<E> il) noexcept; template<class E> constexpr const E* end(initializer_list<E> il) noexcept;}
|
||
|
||
[1](#initializer.list.syn-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L4686)
|
||
|
||
An object of type initializer_list<E> provides access to an array of
|
||
objects of type const E[.](#initializer.list.syn-1.sentence-1)
|
||
|
||
[*Note [1](#initializer.list.syn-note-1)*:
|
||
|
||
A pair of pointers or a pointer plus
|
||
a length would be obvious representations for initializer_list[.](#initializer.list.syn-1.sentence-2)
|
||
|
||
initializer_list is used to implement initializer lists as specified
|
||
in [[dcl.init.list]](dcl.init.list "9.5.5 List-initialization")[.](#initializer.list.syn-1.sentence-3)
|
||
|
||
Copying an initializer_list does not copy the underlying
|
||
elements[.](#initializer.list.syn-1.sentence-4)
|
||
|
||
â *end note*]
|
||
|
||
[2](#initializer.list.syn-2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L4697)
|
||
|
||
If an explicit specialization or partial specialization ofinitializer_list is declared, the program is ill-formed[.](#initializer.list.syn-2.sentence-1)
|
||
|
||
### [17.11.3](#cons) Initializer list constructors [[support.initlist.cons]](support.initlist.cons)
|
||
|
||
[ð](#lib:initializer_list,constructor)
|
||
|
||
`constexpr initializer_list() noexcept;
|
||
`
|
||
|
||
[1](#cons-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L4709)
|
||
|
||
*Postconditions*: size() == 0[.](#cons-1.sentence-1)
|
||
|
||
### [17.11.4](#access) Initializer list access [[support.initlist.access]](support.initlist.access)
|
||
|
||
[ð](#lib:begin,initializer_list)
|
||
|
||
`constexpr const E* begin() const noexcept;
|
||
`
|
||
|
||
[1](#access-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L4722)
|
||
|
||
*Returns*: A pointer to the beginning of the array[.](#access-1.sentence-1)
|
||
|
||
If size() == 0 the
|
||
values of begin() and end() are unspecified but they shall be
|
||
identical[.](#access-1.sentence-2)
|
||
|
||
[ð](#lib:end,initializer_list)
|
||
|
||
`constexpr const E* end() const noexcept;
|
||
`
|
||
|
||
[2](#access-2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L4735)
|
||
|
||
*Returns*: begin() + size()[.](#access-2.sentence-1)
|
||
|
||
[ð](#lib:size,initializer_list)
|
||
|
||
`constexpr size_t size() const noexcept;
|
||
`
|
||
|
||
[3](#access-3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L4746)
|
||
|
||
*Returns*: The number of elements in the array[.](#access-3.sentence-1)
|
||
|
||
[4](#access-4)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L4750)
|
||
|
||
*Complexity*: Constant time[.](#access-4.sentence-1)
|
||
|
||
### [17.11.5](#range) Initializer list range access [[support.initlist.range]](support.initlist.range)
|
||
|
||
[ð](#lib:begin(initializer_list%3cE%3e))
|
||
|
||
`template<class E> constexpr const E* begin(initializer_list<E> il) noexcept;
|
||
`
|
||
|
||
[1](#range-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L4763)
|
||
|
||
*Returns*: il.begin()[.](#range-1.sentence-1)
|
||
|
||
[ð](#lib:end(initializer_list%3cE%3e))
|
||
|
||
`template<class E> constexpr const E* end(initializer_list<E> il) noexcept;
|
||
`
|
||
|
||
[2](#range-2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L4774)
|
||
|
||
*Returns*: il.end()[.](#range-2.sentence-1)
|