Namespaces
Variants
Actions

std::ranges::view_interface<D>::data

From cppreference.com
 
 
Ranges library
 
 
constexpr auto data()
    requires std::contiguous_iterator <ranges::iterator_t <D>>;
(1) (since C++20)
constexpr auto data() const

    requires ranges::range <const D> &&

        std::contiguous_iterator <ranges::iterator_t <const D>>;
(2) (since C++20)

The default implementation of data() member function obtains the address denoted by the beginning iterator via std::to_address, which is also the lowest address of the contiguous storage (implied by contiguous_iterator) referenced by the view of the derived type when the view is not empty.

1) Let derived be static_cast<D&>(*this). Equivalent to return std::to_address (ranges::begin (derived));.
2) Same as (1), except that derived is static_cast<const D&>(*this).

[edit] Return value

The address denoted by the beginning iterator.

[edit] Notes

Following derived types may use the default implementation of data():

Following types are derived from std::ranges::view_interface and do not declare their own data() member function, but they cannot use the default implementation, because their iterator types never satisfy contiguous_iterator:

[edit] Example

Run this code
#include <array>
#include <iostream>
#include <ranges>
#include <string_view>
 
int main() {
 constexpr std::string_view str { "Hello, C++20!" };
 std::cout << (str | std::views::drop (7)).data() << '\n';
 constexpr static std::array a { 1,2,3,4,5 };
 constexpr auto v { a | std::views::take (3) };
 static_assert( &a[0] == v.data() );
}

Output:

C++20!

[edit] See also

(C++17)
obtains the pointer to the underlying array
(function template) [edit]
obtains a pointer to the beginning of a contiguous range
(customization point object)[edit]
obtains a pointer to the beginning of a read-only contiguous range
(customization point object)[edit]
(C++20)
obtains a raw pointer from a pointer-like type
(function template) [edit]
Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/ranges/view_interface/data&oldid=182208"

AltStyle によって変換されたページ (->オリジナル) /