| ||||||||||||||||||||||
| Range primitives | |||||||
| |||||||
| Range concepts | |||||||||||||||||||
| |||||||||||||||||||
| Range factories | |||||||||
| |||||||||
| Range adaptors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Helper items | |||||||||||||||||
| |||||||||||||||||
constexprauto data() requiresstd::contiguous_iterator<ranges::iterator_t<D>>; | (1) | (since C++20) |
constexprauto data()const requiresranges::range<const D>&& | (2) | (since C++20) |
The default implementation ofdata() member function obtains the address denoted by the beginning iterator viastd::to_address, which is also the lowest address of the contiguous storage (implied bycontiguous_iterator) referenced by the view of the derived type when the view is not empty.
derived bestatic_cast<D&>(*this). Equivalent toreturnstd::to_address(ranges::begin(derived));.derived isstatic_cast<const D&>(*this).Contents |
The address denoted by the beginning iterator.
Following derived types may use the default implementation ofdata():
Following types are derived fromstd::ranges::view_interface and do not declare their owndata() member function, but they cannot use the default implementation, because their iterator types never satisfycontiguous_iterator:
#include <array>#include <iostream>#include <ranges>#include <string_view> int main(){constexprstd::string_view str{"Hello, C++20!"};std::cout<<(str| std::views::drop(7)).data()<<'\n';constexprstaticstd::array a{1,2,3,4,5};constexprauto v{ a| std::views::take(3)}; static_assert(&a[0]== v.data());}
Output:
C++20!
(C++17) | obtains the pointer to the underlying array (function template)[edit] |
(C++20) | obtains a pointer to the beginning of a contiguous range (customization point object)[edit] |
(C++20) | 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] |