Iterator concepts | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Iterator primitives | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Algorithm concepts and utilities | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Indirect callable concepts | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Common algorithm requirements | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Utilities | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Iterator adaptors | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
Defined in header <array> | ||
Defined in header <deque> | ||
Defined in header <flat_map> | ||
Defined in header <flat_set> | ||
Defined in header <forward_list> | ||
Defined in header <inplace_vector> | ||
Defined in header <iterator> | ||
Defined in header <list> | ||
Defined in header <map> | ||
Defined in header <regex> | ||
Defined in header <set> | ||
Defined in header <span> | ||
Defined in header <string> | ||
Defined in header <string_view> | ||
Defined in header <unordered_map> | ||
Defined in header <unordered_set> | ||
Defined in header <vector> | ||
template<class C> constexprauto data( C& c)-> decltype(c.data()); | (1) | (since C++17) |
template<class C> constexprauto 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> constexprconst 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 range.
Contents |
c | - | a container or view with adata() member function |
array | - | an array of arbitrary type |
il | - | anstd::initializer_list |
The overload forstd::initializer_list is necessary because it does not have a member functiondata
.
Feature-test macro | Value | Std | Feature |
---|---|---|---|
__cpp_lib_nonmember_container_access | 201411L | (C++17) | std::size(),std::data() , andstd::empty() |
First version |
---|
template<class C>constexprauto data(C& c)-> decltype(c.data()){return c.data();} |
Second version |
template<class C>constexprauto 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>constexprconst E* data(std::initializer_list<E> il)noexcept{return il.begin();} |
#include <cstring>#include <iostream>#include <string> int main(){std::string s{"Hello world!\n"}; char a[20];// storage for a C-style stringstd::strcpy(a, std::data(s));// [s.data(), s.data() + s.size()] is guaranteed to be an NTBS since C++11 std::cout<< a;}
Output:
Hello world!
(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] |