Spec-Zone.ru › C++

std::initializer_list<T>::data

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

begin
(C++11)
returns a pointer to the first element
(public member function)
end
(C++11)
returns a pointer to one past the last element
(public member function)

© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/cpp/utility/initializer_list/data

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API