tetl
0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
distance.hpp
Go to the documentation of this file.
1
// SPDX-License-Identifier: BSL-1.0
2
3
#ifndef TETL_ITERATOR_DISTANCE_HPP
4
#define TETL_ITERATOR_DISTANCE_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
15
template
<
typename
It>
16
constexpr
auto
distance
(It first, It last) ->
typename
iterator_traits<It>::difference_type
17
{
18
using
category =
typename
iterator_traits<It>::iterator_category
;
19
static_assert
(
is_base_of_v<input_iterator_tag, category>
);
20
21
if
constexpr
(
is_base_of_v<random_access_iterator_tag, category>
) {
22
return
last - first;
23
}
else
{
24
auto
result =
typename
iterator_traits<It>::difference_type
{};
25
while
(first != last) {
26
++first;
27
++result;
28
}
29
return
result;
30
}
31
}
32
33
}
// namespace etl
34
35
#endif
// TETL_ITERATOR_DISTANCE_HPP
tags.hpp
etl::distance
constexpr auto distance(It first, It last) -> typename iterator_traits< It >::difference_type
Returns the number of hops from first to last.
Definition
distance.hpp:16
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
distance.hpp
Generated on Sat Mar 8 2025 16:19:59 for tetl by
1.14.0