tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
incrementable_traits.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2// SPDX-FileCopyrightText: Copyright (C) 2023 Tobias Hienzsch
3
4#ifndef TETL_ITERATOR_INCREMENTABLE_TRAITS_HPP
5#define TETL_ITERATOR_INCREMENTABLE_TRAITS_HPP
6
7#include <etl/_concepts/integral.hpp>
8#include <etl/_cstddef/ptrdiff_t.hpp>
9#include <etl/_type_traits/declval.hpp>
10#include <etl/_type_traits/is_object.hpp>
11#include <etl/_type_traits/make_signed.hpp>
12
13namespace etl {
14
15namespace detail {
16template <typename T>
17concept has_difference_type = requires { typename T::difference_type; };
18} // namespace detail
19
20template <typename I>
22
23template <typename T>
25
26template <typename T>
27 requires etl::is_object_v<T>
29 using difference_type = etl::ptrdiff_t;
30};
31
32template <typename T>
33 requires detail::has_difference_type<T>
35 using difference_type = typename T::difference_type;
36};
37
38// clang-format off
39template <typename T>
40 requires(not detail::has_difference_type<T>) and requires(T const& a, T const& b) {
41 { a - b } -> etl::integral;
42 }
43struct incrementable_traits<T> {
44 using difference_type = etl::make_signed_t<decltype(etl::declval<T>() - etl::declval<T>())>;
45};
46
47// clang-format on
48
49} // namespace etl
50
51#endif // TETL_ITERATOR_INCREMENTABLE_TRAITS_HPP
Definition adjacent_find.hpp:9
Definition incrementable_traits.hpp:21