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