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
3#ifndef TETL_RANGES_SIZE_HPP
4#define TETL_RANGES_SIZE_HPP
5
12
13namespace etl::ranges {
14
15namespace size_cpo {
16
17auto size(auto&) -> void = delete;
18auto size(auto const&) -> void = delete;
19
20template <typename T>
21concept has_member_size = not etl::ranges::disable_sized_range<etl::remove_cv_t<T>> and requires(T&& t) {
22 { decay_copy(t.size()) } -> etl::integral;
23};
24
25// clang-format off
26template <typename T>
27concept has_adl_size = not has_member_size<T> and not etl::ranges::disable_sized_range<etl::remove_cv_t<T>> and requires(T&& t) {
28 { decay_copy(size(t)) } -> etl::integral;
29};
30// clang-format on
31
32struct fn {
33 template <typename T, etl::size_t Size>
34 [[nodiscard]] constexpr auto operator()(etl::c_array<T, Size>& /*t*/) const noexcept
35 {
36 return Size;
37 }
38
39 template <typename T, etl::size_t Size>
40 [[nodiscard]] constexpr auto operator()(etl::c_array<T, Size>&& /*t*/) const noexcept
41 {
42 return Size;
43 }
44
45 template <has_member_size T>
46 [[nodiscard]] constexpr auto operator()(T&& t) const noexcept(noexcept(decay_copy(t.size())))
47 {
48 return decay_copy(t.size());
49 }
50
51 template <has_adl_size T>
52 [[nodiscard]] constexpr auto operator()(T&& t) const noexcept(noexcept(decay_copy(size(t))))
53 {
54 return decay_copy(size(t));
55 }
56
57 auto operator()(auto&&) const -> void = delete;
58};
59
60} // namespace size_cpo
61
62inline namespace cpo {
64inline constexpr auto size = size_cpo::fn{};
65} // namespace cpo
66
67} // namespace etl::ranges
68
69#endif // TETL_RANGES_SIZE_HPP
ValueType[Size] c_array
Definition c_array.hpp:12
constexpr auto disable_sized_range
Definition disable_sized_range.hpp:10
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 size
Definition size.hpp:64
Definition ranges_in_fun_result.hpp:11