|
pstore2
|
Provides pointer_based_iterator<> an iterator wrapper for pointers. More...
#include <cstddef>#include <iterator>#include <type_traits>

Go to the source code of this file.
Classes | |
| class | pstore::pointer_based_iterator< T > |
Functions | |
| template<typename T > | |
| pointer_based_iterator< T > | pstore::operator+ (pointer_based_iterator< T > const i, typename pointer_based_iterator< T >::difference_type const n) noexcept |
Move an iterator i forwards by distance n. More... | |
| template<typename T > | |
| pointer_based_iterator< T > | pstore::operator+ (typename pointer_based_iterator< T >::difference_type const n, pointer_based_iterator< T > const i) noexcept |
Move an iterator i forwards by distance n. More... | |
| template<typename T > | |
| pointer_based_iterator< T > | pstore::operator- (pointer_based_iterator< T > const i, typename pointer_based_iterator< T >::difference_type const n) noexcept |
Move an iterator i backwards by distance n. More... | |
| template<typename T > | |
| pointer_based_iterator< T >::difference_type | pstore::operator- (pointer_based_iterator< T > b, pointer_based_iterator< T > a) noexcept |
Provides pointer_based_iterator<> an iterator wrapper for pointers.
Pointers to an array make perfectly good random access iterators. However there are a few of minor niggles with their usage.
First, pointers sometimes take the value nullptr to indicate the end of a sequence. Consider the POSIX readdir() API or a traditional singly-linked list where the last element of the list has a 'next' pointer of nullptr.
Second, there’s no easy way to portably add debug-time checks to raw pointers. Having a class allows us to sanity-check the value of the pointer relative to the container to which it points.
Third, our style guide (and clang-tidy) promotes the use of explicit '*' when declaring an auto variable of pointer type. This is good, but if we're declarating the result type of a standard library function that returns an iterator we would prefer to avoid hard-wiring the type as a pointer and instead stick with an abstract 'iterator'.
The pointer_based_iterator<> class is intended to resolve both of these "problems" by providing a random access iterator wrapper around a pointer.
|
inlinenoexcept |
Move an iterator i forwards by distance n.
n can be both positive or negative.
| i | The iterator to be moved. |
| n | The distance by which iterator i should be moved. |
|
inlinenoexcept |
Move an iterator i forwards by distance n.
n can be both positive or negative.
| i | The iterator to be moved. |
| n | The distance by which iterator i should be moved. |
|
inlinenoexcept |
Move an iterator i backwards by distance n.
n can be both positive or negative.
| i | The iterator to be moved. |
| n | The distance by which iterator i should be moved. |
1.8.13