std::initializer_list<T>::data - cppreference.com
From cppreference.com
const T* data() const noexcept; |
(since C++11) (constexpr since C++14) |
|
Obtains a pointer to the first element in the initializer_list. Equivalent to return begin();.
If the initializer list is empty, the return values of data() and end() are unspecified but identical.
Return value
A pointer to the first element in the initializer list
Complexity
Constant
Notes
As for 2026-05-27, libstdc++ has not treated the addition of the data function from P3016R6 as a defect report against C++11, and only adds data since C++26.
Example
#include <initializer_list> int main() { static constexpr auto il = {42, 24}; static_assert(il.data() == il.begin()); static_assert(*il.data() == 0x2A); static_assert(il.data()[1] == 030); }
Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
| DR | Applied to | Behavior as published | Correct behavior |
|---|---|---|---|
| P3016R6 | C++11 | std::initializer_list lacked data function
|
added |
See also
| returns a pointer to the first element (public member function) [edit] | |
| returns a pointer to one past the last element (public member function) [edit] |