Defined in header <iterator> | ||
|---|---|---|
template <class C> constexpr auto data(C& c) -> decltype(c.data()); | (1) | (since C++17) |
template <class C> constexpr auto data(const C& c) -> decltype(c.data()); | (2) | (since C++17) |
template <class T, std::size_t N> constexpr T* data(T (&array)[N]) noexcept; | (3) | (since C++17) |
template <class E> constexpr const E* data(std::initializer_list<E> il) noexcept; | (4) | (since C++17) |
Returns a pointer to the block of memory containing the elements of the container.
c.data()
array
il.begin()
| c | - | a container with a data() method |
| array | - | an array of arbitrary type |
| il | - | an initializer list |
A pointer to the block of memory containing the elements of the container.
noexcept specification: noexceptIn addition to being included in <iterator>, std::data is guaranteed to become available if any of the following headers are included: <array>, <deque>, <forward_list>, <list>, <map>, <regex>, <set>, <string>, <unordered_map>, <unordered_set>, and <vector>.
| First version |
|---|
template <class C>
constexpr auto data(C& c) -> decltype(c.data())
{
return c.data();
} |
| Second version |
template <class C>
constexpr auto data(const C& c) -> decltype(c.data())
{
return c.data();
} |
| Third version |
template <class T, std::size_t N>
constexpr T* data(T (&array)[N]) noexcept
{
return array;
} |
| Fourth version |
template <class E>
constexpr const E* data(std::initializer_list<E> il) noexcept
{
return il.begin();
} |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
http://en.cppreference.com/w/cpp/iterator/data