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
40template <typename T>
41concept SomeStoppable = requires(T v) {
42 { v.requestStop() } -> std::same_as<void>;
43};
44
50template <typename T>
51concept SomeCancellable = requires(T v) {
52 { v.cancel() } -> std::same_as<void>;
53};
54
60template <typename T>
61concept SomeAwaitable = requires(T v) {
62 { v.wait() } -> std::same_as<void>;
63};
64
70template <typename T>
71concept SomeAbortable = requires(T v) {
72 { v.abort() } -> std::same_as<void>;
73};
74
80template <typename T>
82
88template <typename T>
89concept SomeOperationWithData = SomeOperation<T> and requires(T v) {
90 { v.get() };
91};
92
98template <typename T>
99concept SomeForceInvocableOperation = SomeOperation<T> and requires(T v) {
100 { v.invoke() };
101};
102
108template <typename T>
110
116template <typename T>
118
124template <typename T>
125concept SomeOutcome = requires(T v) {
126 { v.getOperation() } -> SomeOperation;
127};
128
134template <typename T>
135concept SomeStopToken = requires(T v) {
136 { v.isStopRequested() } -> std::same_as<bool>;
137};
138
145template <typename T>
146concept SomeYieldStopSource = requires(T v, boost::asio::yield_context yield) {
147 { v[yield] } -> SomeStopToken;
148};
149
155template <typename T>
156concept SomeSimpleStopSource = requires(T v) {
157 { v.getToken() } -> SomeStopToken;
158};
159
165template <typename T>
167
173template <typename T>
174concept SomeStopSourceProvider = requires(T v) {
175 { v.getStopSource() } -> SomeStopSource;
176};
177
183template <typename T>
185
191template <typename T>
192concept SomeHandlerWithoutStopToken = requires(T fn) {
193 { std::invoke(fn) };
194};
195
202template <typename T, typename... Args>
203concept SomeHandlerWith = requires(T fn) {
204 { std::invoke(fn, std::declval<Args>()...) };
205};
206
212template <typename T>
213concept SomeStdDuration = requires {
214 // Thank you Ed Catmur for this trick.
215 // See
216 // https://stackoverflow.com/questions/74383254/concept-that-models-only-the-stdchrono-duration-types
217 []<typename Rep, typename Period>( //
218 std::type_identity<std::chrono::duration<Rep, Period>>
219 ) {}(std::type_identity<std::decay_t<T>>());
220};
221
227template <typename T>
228concept SomeStdOptional = requires {
229 []<typename Type>( //
230 std::type_identity<std::optional<Type>>
231 ) {}(std::type_identity<std::decay_t<T>>());
232};
233
239template <typename T>
240concept SomeOptStdDuration = SomeStdOptional<T> and SomeStdDuration<decltype(T{}.value())>;
241
248template <typename T, typename Erased>
249concept NotSameAs = not std::is_same_v<std::decay_t<T>, Erased>;
250
257template <typename T, typename Erased>
258concept RValueNotSameAs = requires(T&& t) {
259 requires std::is_rvalue_reference_v<decltype(t)>;
260 requires NotSameAs<T, Erased>;
261};
262
263} // namespace util::async
Checks that decayed T is not of the same type as Erased.
Definition Concepts.hpp:249
Check that T is an r-value and is not the same type as Erased.
Definition Concepts.hpp:258
Specifies the interface for an operation that can be aborted.
Definition Concepts.hpp:71
Specifies the interface for an operation that can be awaited.
Definition Concepts.hpp:61
Specifies the interface for an operation that can be cancelled.
Definition Concepts.hpp:117
Specifies the interface for an entity that can be cancelled.
Definition Concepts.hpp:51
Concept that identifies types derived from ExecutionContextTag.
Definition Concepts.hpp:33
Specifies the interface for an operation that can force-invoked.
Definition Concepts.hpp:99
Specifies the interface for a handler that can be invoked with the specified args.
Definition Concepts.hpp:203
Specifies the interface for a handler that is invocable without a stop token.
Definition Concepts.hpp:192
Specifies the interface for an operation that produces data.
Definition Concepts.hpp:89
Specifies the interface for an operation.
Definition Concepts.hpp:81
Specifies that the type must be some std::duration wrapped in an optional.
Definition Concepts.hpp:240
Specifies the interface for an outcome (promise).
Definition Concepts.hpp:125
Specifies the interface for a simple stop source.
Definition Concepts.hpp:156
Specifies that the type must be some std::duration.
Definition Concepts.hpp:213
Specifies that the type must be some std::optional.
Definition Concepts.hpp:228
Specifies the interface for a provider of stop sources.
Definition Concepts.hpp:174
Specifies the interface for a stop source.
Definition Concepts.hpp:166
Specifies the interface for a stop token.
Definition Concepts.hpp:135
Specifies the interface for an operation that can be stopped.
Definition Concepts.hpp:109
Specifies the interface for an outcome (promise) that can be stopped.
Definition Concepts.hpp:184
Specifies the interface for an entity that can be stopped.
Definition Concepts.hpp:41
Specifies the interface for a stop source that produces tokens from a boost::asio::yield_context.
Definition Concepts.hpp:146
This namespace implements an async framework built on top of execution contexts.
Definition AnyExecutionContext.hpp:18
Tag type for identifying execution context types.
Definition Concepts.hpp:20