di
0.1.0
Loading...
Searching...
No Matches
empty.h
Go to the documentation of this file.
1
#pragma once
2
3
#include "
di/container/concepts/forward_iterator.h
"
4
#include "
di/container/interface/begin.h
"
5
#include "
di/container/interface/end.h
"
6
#include "
di/container/interface/size.h
"
7
#include "
di/container/meta/container_iterator.h
"
8
#include "
di/function/tag_invoke.h
"
9
10
namespace
di::container
{
11
struct
EmptyFunction
;
12
13
namespace
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
29
struct
EmptyFunction
:
function::pipeline::EnablePipeline
{
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
{
40
return
bool(
container::begin
(
container
) ==
container::end
(
container
));
41
}
42
}
43
};
44
45
constexpr
inline
auto
empty
=
EmptyFunction
{};
46
}
47
48
namespace
di
{
49
using
container::empty
;
50
}
begin.h
container_iterator.h
end.h
forward_iterator.h
di::container
Definition
sequence.h:12
di::container::empty
constexpr auto empty
Definition
empty.h:45
di::container::size
constexpr auto size
Definition
size.h:62
di::container::end
constexpr auto end
Definition
end.h:55
di::container::begin
constexpr auto begin
Definition
begin.h:52
di::function::tag_invoke_ns::tag_invoke
constexpr tag_invoke_detail::TagInvokeFn tag_invoke
Definition
tag_invoke.h:22
di
Definition
any_storable.h:9
size.h
di::container::EmptyFunction
Definition
empty.h:29
di::function::pipeline::EnablePipeline
Definition
pipeable.h:8
tag_invoke.h
di
container
interface
empty.h
Generated by
1.13.2