Clio  develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
Concepts.hpp
1#pragma once
2
3#include <boost/asio/spawn.hpp>
4
5#include <chrono>
6#include <concepts>
7#include <functional>
8#include <optional>
9#include <type_traits>
10
11namespace util::async {
12
21 virtual ~ExecutionContextTag() = default;
22};
23
32template <typename T>
33concept SomeExecutionContext = std::derived_from<std::remove_cvref_t<T>, ExecutionContextTag>;
34
38template <typename T>
39concept SomeStoppable = requires(T v) {
40 { v.requestStop() } -> std::same_as<void>;
41};
42
46template <typename T>
47concept SomeCancellable = requires(T v) {
48 { v.cancel() } -> std::same_as<void>;
49};
50
54template <typename T>
55concept SomeAwaitable = requires(T v) {
56 { v.wait() } -> std::same_as<void>;
57};
58
62template <typename T>
63concept SomeAbortable = requires(T v) {
64 { v.abort() } -> std::same_as<void>;
65};
66
70template <typename T>
72
76template <typename T>
77concept SomeOperationWithData = SomeOperation<T> and requires(T v) {
78 { v.get() };
79};
80
84template <typename T>
85concept SomeForceInvocableOperation = SomeOperation<T> and requires(T v) {
86 { v.invoke() };
87};
88
92template <typename T>
94
98template <typename T>
100
104template <typename T>
105concept SomeOutcome = requires(T v) {
106 { v.getOperation() } -> SomeOperation;
107};
108
112template <typename T>
113concept SomeStopToken = requires(T v) {
114 { v.isStopRequested() } -> std::same_as<bool>;
115};
116
120template <typename T>
121concept SomeYieldStopSource = requires(T v, boost::asio::yield_context yield) {
122 { v[yield] } -> SomeStopToken;
123};
124
128template <typename T>
129concept SomeSimpleStopSource = requires(T v) {
130 { v.getToken() } -> SomeStopToken;
131};
132
136template <typename T>
138
142template <typename T>
143concept SomeStopSourceProvider = requires(T v) {
144 { v.getStopSource() } -> SomeStopSource;
145};
146
150template <typename T>
152
156template <typename T>
157concept SomeHandlerWithoutStopToken = requires(T fn) {
158 { std::invoke(fn) };
159};
160
164template <typename T, typename... Args>
165concept SomeHandlerWith = requires(T fn) {
166 { std::invoke(fn, std::declval<Args>()...) };
167};
168
172template <typename T>
173concept SomeStdDuration = requires {
174 // Thank you Ed Catmur for this trick.
175 // See
176 // https://stackoverflow.com/questions/74383254/concept-that-models-only-the-stdchrono-duration-types
177 []<typename Rep, typename Period>( //
178 std::type_identity<std::chrono::duration<Rep, Period>>
179 ) {}(std::type_identity<std::decay_t<T>>());
180};
181
185template <typename T>
186concept SomeStdOptional = requires {
187 []<typename Type>( //
188 std::type_identity<std::optional<Type>>
189 ) {}(std::type_identity<std::decay_t<T>>());
190};
191
195template <typename T>
196concept SomeOptStdDuration = SomeStdOptional<T> and SomeStdDuration<decltype(T{}.value())>;
197
201template <typename T, typename Erased>
202concept NotSameAs = not std::is_same_v<std::decay_t<T>, Erased>;
203
207template <typename T, typename Erased>
208concept RValueNotSameAs = requires(T&& t) {
209 requires std::is_rvalue_reference_v<decltype(t)>;
210 requires NotSameAs<T, Erased>;
211};
212
213} // namespace util::async
Checks that decayed T s not of the same type as Erased.
Definition Concepts.hpp:202
Check that T is an r-value and is not the same type as Erased.
Definition Concepts.hpp:208
Specifies the interface for an operation that can be aborted.
Definition Concepts.hpp:63
Specifies the interface for an operation that can be awaited.
Definition Concepts.hpp:55
Specifies the interface for an operation that can be cancelled.
Definition Concepts.hpp:99
Specifies the interface for an entity that can be cancelled.
Definition Concepts.hpp:47
Concept that identifies types derived from ExecutionContextTag.
Definition Concepts.hpp:33
Specifies the interface for an operation that can force-invoked.
Definition Concepts.hpp:85
Specifies the interface for a handler that can be invoked with the specified args.
Definition Concepts.hpp:165
Specifies the interface for a handler that can be stopped.
Definition Concepts.hpp:157
Specifies the interface for an operation.
Definition Concepts.hpp:77
Specifies the interface for an operation.
Definition Concepts.hpp:71
Specifies that the type must be some std::duration wrapped in an optional.
Definition Concepts.hpp:196
Specifies the interface for an outcome (promise).
Definition Concepts.hpp:105
Specifies the interface for a simple stop token.
Definition Concepts.hpp:129
Specifies that the type must be some std::duration.
Definition Concepts.hpp:173
Specifies that the type must be some std::optional.
Definition Concepts.hpp:186
Specifies the interface for a provider of stop sources.
Definition Concepts.hpp:143
Specifies the interface for a stop source.
Definition Concepts.hpp:137
Specifies the interface for a stop token.
Definition Concepts.hpp:113
Specifies the interface for an operation that can be stopped.
Definition Concepts.hpp:93
Specifies the interface for an outcome (promise) that can be stopped.
Definition Concepts.hpp:151
Specifies the interface for an entity that can be stopped.
Definition Concepts.hpp:39
Specifies the interface for a stop token that internally uses a boost::asio::yield_context.
Definition Concepts.hpp:121
This namespace implements an async framework built on top of execution contexts.
Definition AnyExecutionContext.hpp:17
Tag type for identifying execution context types.
Definition Concepts.hpp:20