tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
size.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2// SPDX-FileCopyrightText: Copyright (C) 2024 Tobias Hienzsch
3
4#ifndef TETL_RANGES_SIZE_HPP
5#define TETL_RANGES_SIZE_HPP
6
7#include <etl/_array/c_array.hpp>
8#include <etl/_concepts/integral.hpp>
9#include <etl/_ranges/decay_copy.hpp>
10#include <etl/_ranges/disable_sized_range.hpp>
11#include <etl/_ranges/iterator_t.hpp>
12#include <etl/_type_traits/remove_cv.hpp>
13
14namespace etl::ranges {
15
16namespace size_cpo {
17
18auto size(auto&) -> void = delete;
19auto size(auto const&) -> void = delete;
20
21template <typename T>
22concept has_member_size = not etl::ranges::disable_sized_range<etl::remove_cv_t<T>> and requires(T&& t) {
23 { decay_copy(t.size()) } -> etl::integral;
24};
25
26// clang-format off
27template <typename T>
28concept has_adl_size = not has_member_size<T> and not etl::ranges::disable_sized_range<etl::remove_cv_t<T>> and requires(T&& t) {
29 { decay_copy(size(t)) } -> etl::integral;
30};
31// clang-format on
32
33struct fn {
34 template <typename T, etl::size_t Size>
35 [[nodiscard]] constexpr auto operator()(etl::c_array<T, Size>& /*t*/) const noexcept
36 {
37 return Size;
38 }
39
40 template <typename T, etl::size_t Size>
41 [[nodiscard]] constexpr auto operator()(etl::c_array<T, Size>&& /*t*/) const noexcept
42 {
43 return Size;
44 }
45
46 template <has_member_size T>
47 [[nodiscard]] constexpr auto operator()(T&& t) const noexcept(noexcept(decay_copy(t.size())))
48 {
49 return decay_copy(t.size());
50 }
51
52 template <has_adl_size T>
53 [[nodiscard]] constexpr auto operator()(T&& t) const noexcept(noexcept(decay_copy(size(t))))
54 {
55 return decay_copy(size(t));
56 }
57
58 auto operator()(auto&&) const -> void = delete;
59};
60
61} // namespace size_cpo
62
63inline namespace cpo {
64/// \ingroup ranges
65inline constexpr auto size = size_cpo::fn{};
66} // namespace cpo
67
68} // namespace etl::ranges
69
70#endif // TETL_RANGES_SIZE_HPP
constexpr auto size
Definition size.hpp:65
Definition ranges_iter_move.hpp:61
Definition ranges_in_fun_result.hpp:12
Definition adjacent_find.hpp:9