chsvlib
chsv helper source code

◆ offset_iterator_begin()

constexpr unspecified Chusov::Memory::offset_iterator_begin ( Iterator  it)
constexprnoexcept

Returns an object of an unspecified type which is an iterator of the same category as the parameter but redefines increment, decrement and comparison operators to keep the current offset from the initial position.

Template Parameters
IteratorA type of it. It can be any iterator satisfying the Iterator requirements.
Parameters
itAn iterator to adapt to the counting operator
Returns
An iterator of unspecified type of the same category as it which delegates all calls except for the comparison operators to it and redefines the comparison operators together with shifting operators, e.g. increment, to take into account offset of the resulting iterator from the initial state defined by it. The initial position is set to zero by this function, that is unlike the offset_iterator_end counterpart.

The offset_iterator_begin and offset_iterator_end functions allow iterations inside code that has a range based interface (i.e. one that given by a pair of a beginning and an ending iterator) based on only a given beginning iterator and a number of elements to read, even when the given iterator is an InputIterator or an OutputIterator.

The function is marked noexcept if a copy-construction of it is noexcept.

#include <cstddef>
#include <vector>
#include <iostream>
#include <iterator>
template <class Iterator>
void show_all(Iterator begin, Iterator end)
{
for (auto it = begin; it != end; ++it)
std::cout << *it;
}
template <class Iterator>
void show_all(Iterator iter, std::size_t count)
{
using namespace Chusov::Memory;
show_all(offset_iterator_begin(iter), offset_iterator_end(iter, count));
}
int main(int, char**)
{
std::vector<int> v = {1, 2, 3, 4, 5};
show_all(std::begin(v) + 1, v.size() - 2);
std::cout << '\n';
return 0;
}
Advanced functionality and C++ objects for working with memory.
constexpr auto offset_iterator_end(Iterator it, difference_type offset) noexcept
Returns an object of an unspecified type which is an iterator of the same category as the parameter b...
constexpr unspecified offset_iterator_begin(Iterator it) noexcept
Returns an object of an unspecified type which is an iterator of the same category as the parameter b...
A namespace of functions and components used to work with memory.
Definition: chsvmem.h:71

Output:

234
See also
offset_iterator_end