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