Przejdź do głównej zawartości

std::span data() method

constexpr pointer data() const noexcept;

Returns a pointer to the beginning of the sequence.

Parameters

(none)

Return value

A pointer to the beginning of sequence.

Complexity

Constant - O(1).

Exceptions

(none)

Notes

For a span s, the expression s.data() is equivalent to *s.begin() and s[0].

Example

Main.cpp
#include <span>
#include <iostream>

int main()
{
constexpr char str[] = "ABCDEF\n";

const std::span sp{str};

for (auto n{sp.size()}; n != 2; --n) {
std::cout << sp.last(n).data();
}
}
Output
ABCDEF
BCDEF
CDEF
DEF
EF
F
This article originates from this CppReference page. It was likely altered for improvements or editors' preference. Click "Edit this page" to see all changes made to this document.
Hover to see the original license.

std::span data() method

constexpr pointer data() const noexcept;

Returns a pointer to the beginning of the sequence.

Parameters

(none)

Return value

A pointer to the beginning of sequence.

Complexity

Constant - O(1).

Exceptions

(none)

Notes

For a span s, the expression s.data() is equivalent to *s.begin() and s[0].

Example

Main.cpp
#include <span>
#include <iostream>

int main()
{
constexpr char str[] = "ABCDEF\n";

const std::span sp{str};

for (auto n{sp.size()}; n != 2; --n) {
std::cout << sp.last(n).data();
}
}
Output
ABCDEF
BCDEF
CDEF
DEF
EF
F
This article originates from this CppReference page. It was likely altered for improvements or editors' preference. Click "Edit this page" to see all changes made to this document.
Hover to see the original license.