CARVIEW |
Select Language
HTTP/1.1 301 Moved Permanently
Server: nginx
Date: Sat, 19 Jul 2025 14:22:20 GMT
Content-Type: text/html; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
Location: /reference/initializer_list/initializer_list/
HTTP/1.1 200 OK
Server: nginx
Date: Sat, 19 Jul 2025 14:22:20 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
ETag: W/"6caf-sspjlO80zNZJcC61y3p+IvvWs/M"
Content-Encoding: gzip
This type is used to access the values in a C++ initialization list, which is a list of elements of type
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:
Notice though that this template class is not implicitly defined and the header
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:
Reference
C library:
- <cassert> (assert.h)
- <cctype> (ctype.h)
- <cerrno> (errno.h)
-
<cfenv> (fenv.h)C++11
- <cfloat> (float.h)
-
<cinttypes> (inttypes.h)C++11
- <ciso646> (iso646.h)
- <climits> (limits.h)
- <clocale> (locale.h)
- <cmath> (math.h)
- <csetjmp> (setjmp.h)
- <csignal> (signal.h)
- <cstdarg> (stdarg.h)
-
<cstdbool> (stdbool.h)C++11
- <cstddef> (stddef.h)
-
<cstdint> (stdint.h)C++11
- <cstdio> (stdio.h)
- <cstdlib> (stdlib.h)
- <cstring> (string.h)
-
<ctgmath> (tgmath.h)C++11
- <ctime> (time.h)
-
<cuchar> (uchar.h)C++11
- <cwchar> (wchar.h)
- <cwctype> (wctype.h)
Containers:
-
<array>C++11
- <deque>
-
<forward_list>C++11
- <list>
- <map>
- <queue>
- <set>
- <stack>
-
<unordered_map>C++11
-
<unordered_set>C++11
- <vector>
-
Input/Output:
Multi-threading:
-
<atomic>C++11
-
<condition_variable>C++11
-
<future>C++11
-
<mutex>C++11
-
<thread>C++11
-
Other:
- <algorithm>
- <bitset>
-
<chrono>C++11
-
<codecvt>C++11
- <complex>
- <exception>
- <functional>
-
<initializer_list>C++11
- <iterator>
- <limits>
- <locale>
- <memory>
- <new>
- <numeric>
-
<random>C++11
-
<ratio>C++11
-
<regex>C++11
- <stdexcept>
- <string>
-
<system_error>C++11
-
<tuple>C++11
-
<type_traits>C++11
-
<typeindex>C++11
- <typeinfo>
- <utility>
- <valarray>
<initializer_list>
classes
-
initializer_listC++11
-
initializer_list
-
initializer_list::initializer_listC++11
member functions
-
initializer_list::beginC++11
-
initializer_list::endC++11
-
initializer_list::sizeC++11
-
non-member overloads
-
begin (initializer_list)C++11
-
end (initializer_list)C++11
-
- Reference
- <initializer_list>
- initializer_list
class template
<initializer_list>
std::initializer_list
template<class T> class initializer_list;
Initializer list
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:
|
|
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:
|
|
Template parameters
- T
- Type of the elements.
Aliased as member typeinitializer_list::value_type
.
Member types
member type | definition |
---|---|
value_type | The template parameter (T) |
reference | const T& |
const_reference | const T& |
size_type | size_t |
iterator | const T* |
const_iterator | const T* |
Member functions
- (constructor)
- Construct empty initializer_list (public member function)
- size
- Return size of list (public member function)
- begin
- Return iterator to beginning (public member function)
- end
- Return iterator to end (public member function)
Non-member function overloads
- begin (initializer_list)
- Return iterator to beginning (function template)
- end (initializer_list)
- Return iterator to end (function template)
Home page | Privacy policy
© cplusplus.com, 2000-2025 - All rights reserved - v3.3.4s
Spotted an error? contact us
© cplusplus.com, 2000-2025 - All rights reserved - v3.3.4s
Spotted an error? contact us