|
cxxomfort
rel.20211024
Simple backports for C++ - https://ryan.gulix.cl/fossil.cgi/cxxomfort/
|
Backports related to Standard header <iterator>
Interfaces defined in this section:
begin() , end() .rbegin() .make_reverse_iterator() (C++14).size() .contiguous_iterator_tag (C++20).Non-backport interfaces (cxxomfort::fix):
is_contiguous_access_iterator - A trait check for contiguous access iterators.cdata() accessor , to supplement std::data()static_next(), static_prev() for constexpr -pointer iterator (C++11 onwards).C++11 onward have introduced a number of non-member accessor functions for iterator and container elements in C++. These include global begin/end functions to access arrays, containers and sequences, and a number of accessor functions such as size() that checks for a container, array or sequence's reported size.
Begin / End accessors
begin() / end() : the invocation begin(sequence) returns:
Sequence::iterator or T* in C++<11sequence.begin() when it exists&(sequence[0]) when sequence is a native array with type T(&)[N] rbegin() / rend() : the invocation rbegin(sequence) returns:
Sequence::reverse_iterator in C++<11sequence.rbegin() when it exists&(sequence[N-1]) when sequence is a native array with type Type(&)[N] cbegin() / cend() / crbegin() / crend() : they return the const_iterator or const_pointer (or T const*) version of the above.
Container Accessors
C++17 added the following functions:
size() : the invocation size(sequence) returns:
Sequence::size_type or size_t in C+++<11sequence.size() when it existsstd:distance( sequence.begin(), sequence.end() ) when a member size does not exist (see note below)N when sequence is a native array with type T(&)[N]empty() : the invocation empty(sequence) returns:
bool valuesequence.empty() when it exists0 for arraysdata() : the invocation data(sequence) returns:
T* (or T const*) pointer valuesequence.data() when it existssequence (decayed to pointer) for arraysforward_list. As per cppreference, "Custom overloads of size may be provided for classes and enumerations that do not expose a suitable size() member function, yet can be detected", so these overloads are permitted.Previous to C++20, cxxomfort defines, but can't use, the iterator tag contiguous_iterator_tag . This is a refinement over random_access_iterator_tag used in newer Standards to point out to iterator types that refer to contiguous memory storage (such as raw pointers).
Because it's not possible to redefine member types in std containers and iterators, at present only the following features in cxxomfort make use of the contiguous_iterator_tag type:
cxxomfort::iterator_helper basic_string_view when backported
1.8.13