Namespaces
Variants

std::initializer_list<T>::data

From cppreference.com
 
 
Utilities library
General utilities
Relational operators (deprecated in C++20)
Integer comparison functions
(C++20)(C++20)(C++20)    
(C++20)
Swap and type operations
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
Common vocabulary types
(C++11)
(C++17)
(C++17)
(C++17)
(C++11)
(C++17)
(C++23)



 
 
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

(C++11)
returns a pointer to the first element
(public member function) [edit]
(C++11)
returns a pointer to one past the last element
(public member function) [edit]
Morty Proxy This is a proxified and sanitized view of the page, visit original site.