tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
end.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_RANGES_END_HPP
5#define TETL_RANGES_END_HPP
6
7#include <etl/_iterator/input_or_output_iterator.hpp>
8#include <etl/_iterator/sentinel_for.hpp>
9#include <etl/_ranges/can_borrow.hpp>
10#include <etl/_ranges/decay_copy.hpp>
11#include <etl/_ranges/iterator_t.hpp>
12
13namespace etl::ranges {
14
15namespace end_cpo {
16
17auto end(auto&) -> void = delete;
18auto end(auto const&) -> void = delete;
19
20template <typename T>
21concept has_member_end = ranges::detail::can_borrow<T> and requires(T&& t) {
22 { decay_copy(t.end()) } -> etl::sentinel_for<etl::ranges::iterator_t<T>>;
23};
24
25template <typename T>
26concept has_adl_end = not has_member_end<T> and ranges::detail::can_borrow<T> and requires(T&& t) {
27 { decay_copy(end(t)) } -> etl::sentinel_for<etl::ranges::iterator_t<T>>;
28};
29
30struct fn {
31 template <typename T, etl::size_t Size>
32 requires(sizeof(T) >= 0) // NOLINT(bugprone-sizeof-expression)
33 [[nodiscard]] constexpr auto operator()(T (&t)[Size]) const noexcept
34 {
35 return t + Size;
36 }
37
38 template <has_member_end T>
39 [[nodiscard]] constexpr auto operator()(T&& t) const noexcept(noexcept(decay_copy(t.end())))
40 {
41 return decay_copy(t.end());
42 }
43
44 template <has_adl_end T>
45 [[nodiscard]] constexpr auto operator()(T&& t) const noexcept(noexcept(decay_copy(end(t))))
46 {
47 return decay_copy(end(t));
48 }
49
50 auto operator()(auto&&) const -> void = delete;
51};
52
53} // namespace end_cpo
54
55inline namespace cpo {
56/// \ingroup ranges
57inline constexpr auto end = end_cpo::fn{};
58} // namespace cpo
59
60} // namespace etl::ranges
61
62#endif // TETL_RANGES_END_HPP
constexpr auto end
Definition end.hpp:57
Definition ranges_iter_move.hpp:61
Definition ranges_in_fun_result.hpp:12
Definition adjacent_find.hpp:9