template< class C >
constexpr auto data( C& c ) -> decltype(c.data());
template< class C >
constexpr auto data( const C& c ) -> decltype(c.data());
Returns a pointer to the block of memory containing the elements of the range.
1,2) Returns c.data().
3) Returns array.
4) Returns il.begin().
[edit] Parameters c - a container or view with a data() member function array - an array of arbitrary type il - an std::initializer_list [edit] Return value1,2) c.data()
3) array
4) il.begin()
[edit] Exceptions1) May throw implementation-defined exceptions.
[edit] NotesThe overload for std::initializer_list is necessary because it does not have a member function data
.
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(); }[edit] Example
#include <cstring> #include <iostream> #include <string> int main() { std::string s{"Hello world!\n"}; char a[20]; // storage for a C-style string std::strcpy(a, std::data(s)); // [s.data(), s.data() + s.size()] is guaranteed to be an NTBS since C++11 std::cout << a; }
Output:
[edit] See also obtains a pointer to the beginning of a contiguous rangeRetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4