di 0.1.0
Loading...
Searching...
No Matches
empty.h
Go to the documentation of this file.
1#pragma once
2
9
10namespace di::container {
11struct EmptyFunction;
12
13namespace detail {
14 template<typename T>
15 concept CustomEmpty = concepts::TagInvocableTo<EmptyFunction, bool, T>;
16
17 template<typename T>
18 concept MemberEmpty = requires(T&& container) { static_cast<bool>(container.empty()); };
19
20 template<typename T>
21 concept SizeEmpty = requires(T&& container) { static_cast<bool>(container::size(container) == 0); };
22
23 template<typename T>
24 concept IteratorEmpty = requires(T&& container) {
25 static_cast<bool>(container::begin(container) == container::end(container));
26 } && concepts::ForwardIterator<meta::ContainerIterator<T>>;
27}
28
30 template<typename T>
31 requires(detail::CustomEmpty<T> || detail::MemberEmpty<T> || detail::SizeEmpty<T> || detail::IteratorEmpty<T>)
32 constexpr auto operator()(T&& container) const -> bool {
33 if constexpr (detail::CustomEmpty<T>) {
34 return function::tag_invoke(*this, container);
35 } else if constexpr (detail::MemberEmpty<T>) {
36 return bool(container.empty());
37 } else if constexpr (detail::SizeEmpty<T>) {
38 return container::size(container) == 0;
39 } else {
41 }
42 }
43};
44
45constexpr inline auto empty = EmptyFunction {};
46}
47
48namespace di {
50}
Definition sequence.h:12
constexpr auto empty
Definition empty.h:45
constexpr auto size
Definition size.h:62
constexpr auto end
Definition end.h:55
constexpr auto begin
Definition begin.h:52
constexpr tag_invoke_detail::TagInvokeFn tag_invoke
Definition tag_invoke.h:22
Definition any_storable.h:9
Definition empty.h:29