1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
template<typename InvokerT, typename TagT, typename... Args>
concept MemTagInvocable = requires(InvokerT invoker, Args&&... args) {
std::forward<InvokerT>(invoker).tag_invoke(TagT(), std::forward<Args>(args)...);
};
template<typename InvokerT, typename TagT, typename... Args>
concept FreeTagInvocable = requires(InvokerT invoker, Args&&... args) {
tag_invoke(TagT(), std::forward<InvokerT>(invoker), std::forward<Args>(args)...);
};
template<typename InvokerT, typename TagT, typename... Args>
concept MemTagInvocableOnly =
MemTagInvocable<InvokerT, TagT, Args...> && !FreeTagInvocable<InvokerT, TagT, Args...>;
template<typename InvokerT, typename TagT, typename... Args>
concept FreeTagInvocableOnly =
FreeTagInvocable<InvokerT, TagT, Args...> && !MemTagInvocable<InvokerT, TagT, Args...>;
template<typename InvokerT, typename TagT, typename... Args>
concept TagInvocableAmbiguously =
MemTagInvocable<InvokerT, TagT, Args...> && FreeTagInvocable<InvokerT, TagT, Args...>;
template<typename InvokerT, typename TagT, typename... Args>
concept NoThrowMemTagInvocable = requires(InvokerT invoker, Args&&... args) {
{ std::forward<InvokerT>(invoker).tag_invoke(TagT(), std::forward<Args>(args)...) } noexcept;
};
template<typename InvokerT, typename TagT, typename... Args>
concept NoThrowFreeTagInvocable = requires(InvokerT invoker, Args&&... args) {
{ tag_invoke(TagT(), std::forward<InvokerT>(invoker), std::forward<Args>(args)...) } noexcept;
};
template<typename InvokerT, typename TagT, typename... Args>
concept TagInvocable =
FreeTagInvocable<InvokerT, TagT, Args...> || MemTagInvocable<InvokerT, TagT, Args...>;
template<typename TagT, typename... Args>
struct UnifiedCallOpClosure : public std::tuple<Args&&...> {
explicit constexpr UnifiedCallOpClosure(Args&&... args) :
std::tuple<Args&&...> {std::forward<Args>(args)...} {}
template<TagInvocableAmbiguously<TagT, Args...> InvokerT>
inline friend constexpr auto operator|(
InvokerT&& invoker, const UnifiedCallOpClosure& op
) noexcept(NoThrowFreeTagInvocable<InvokerT, TagT, Args...>) {
return std::apply(
[&](auto&&... args) {
return tag_invoke(
TagT(),
std::forward<InvokerT>(invoker),
std::forward<Args>(args)...
);
},
static_cast<const std::tuple<Args&&...>&>(op)
);
}
template<FreeTagInvocableOnly<TagT, Args...> InvokerT>
inline friend constexpr auto operator|(
InvokerT&& invoker, const UnifiedCallOpClosure& op
) noexcept(NoThrowFreeTagInvocable<InvokerT, TagT, Args...>) {
return std::apply(
[&](auto&&... args) {
return tag_invoke(
TagT(),
std::forward<InvokerT>(invoker),
std::forward<Args>(args)...
);
},
static_cast<const std::tuple<Args&&...>&>(op)
);
}
template<MemTagInvocableOnly<TagT, Args...> InvokerT>
inline friend constexpr auto operator|(
InvokerT&& invoker, const UnifiedCallOpClosure& op
) noexcept(NoThrowMemTagInvocable<InvokerT, TagT, Args...>) {
return std::apply(
[&](auto&&... args) {
return std::forward<InvokerT>(invoker).tag_invoke(
TagT(),
std::forward<Args>(args)...
);
},
static_cast<const std::tuple<Args&&...>&>(op)
);
}
};
template<typename TagT>
struct UnifiedCallOp {
template<typename InvokerT, typename... Args>
requires TagInvocableAmbiguously<InvokerT, TagT, Args...>
inline constexpr auto operator()(
InvokerT&& invoker, Args&&... args
) const noexcept(NoThrowFreeTagInvocable<InvokerT, TagT, Args...>) -> decltype(auto) {
return tag_invoke(TagT(), std::forward<InvokerT>(invoker), std::forward<Args>(args)...);
}
template<typename InvokerT, typename... Args>
requires FreeTagInvocableOnly<InvokerT, TagT, Args...>
inline constexpr auto operator()(
InvokerT&& invoker, Args&&... args
) const noexcept(NoThrowFreeTagInvocable<InvokerT, TagT, Args...>) -> decltype(auto) {
return tag_invoke(TagT(), std::forward<InvokerT>(invoker), std::forward<Args>(args)...);
}
template<typename InvokerT, typename... Args>
requires MemTagInvocableOnly<InvokerT, TagT, Args...>
inline constexpr auto operator()(
InvokerT&& invoker, Args&&... args
) const noexcept(NoThrowMemTagInvocable<InvokerT, TagT, Args...>) -> decltype(auto) {
return std::forward<InvokerT>(invoker).tag_invoke(TagT(), std::forward<Args>(args)...);
}
template<typename... Args>
inline constexpr auto operator()(Args&&... args) const noexcept
-> UnifiedCallOpClosure<TagT, Args...> {
return UnifiedCallOpClosure<TagT, Args...> {std::forward<Args>(args)...};
}
};
|