tetl
0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
advance.hpp
Go to the documentation of this file.
1
// SPDX-License-Identifier: BSL-1.0
2
3
#ifndef TETL_ITERATOR_ADVANCE_HPP
4
#define TETL_ITERATOR_ADVANCE_HPP
5
6
#include <
etl/_iterator/iterator_traits.hpp
>
7
#include <
etl/_iterator/tags.hpp
>
8
#include <
etl/_type_traits/is_base_of.hpp
>
9
10
namespace
etl
{
11
21
template
<
typename
It,
typename
Distance>
22
constexpr
auto
advance
(It& it, Distance n) ->
void
23
{
24
using
category =
typename
iterator_traits<It>::iterator_category
;
25
static_assert
(
is_base_of_v<input_iterator_tag, category>
);
26
27
auto
dist =
typename
iterator_traits<It>::difference_type
(n);
28
if
constexpr
(
is_base_of_v<random_access_iterator_tag, category>
) {
29
it += dist;
30
}
else
{
31
while
(dist > 0) {
32
--dist;
33
++it;
34
}
35
if
constexpr
(
is_base_of_v<bidirectional_iterator_tag, category>
) {
36
while
(dist < 0) {
37
++dist;
38
--it;
39
}
40
}
41
}
42
}
43
44
}
// namespace etl
45
46
#endif
// TETL_ITERATOR_ADVANCE_HPP
tags.hpp
etl::advance
constexpr auto advance(It &it, Distance n) -> void
Increments given iterator it by n elements.
Definition
advance.hpp:22
is_base_of.hpp
iterator_traits.hpp
etl
Definition
adjacent_find.hpp:8
etl::is_base_of_v
constexpr bool is_base_of_v
Definition
is_base_of.hpp:39
etl::iterator_traits
iterator_traits is the type trait class that provides uniform interface to the properties of LegacyIt...
Definition
iterator_traits.hpp:47
include
etl
_iterator
advance.hpp
Generated on Sat Mar 8 2025 16:19:59 for tetl by
1.14.0