Common System 0.2.0
Common interfaces and patterns for system integration
Loading...
Searching...
No Matches
callable.h
Go to the documentation of this file.
1// BSD 3-Clause License
2// Copyright (c) 2025, 🍀☀🌕🌥 🌊
3// See the LICENSE file in the project root for full license information.
4
25#pragma once
26
27#include <concepts>
28#include <type_traits>
29#include <functional>
30#include <string>
31#include <future>
32#include <memory>
33#include <chrono>
34
36
37namespace kcenon::common {
38
39// Forward declarations
40namespace interfaces {
41class IJob;
42}
43
44namespace concepts {
45
61template<typename F, typename... Args>
62concept Invocable = std::invocable<F, Args...>;
63
79template<typename F, typename... Args>
80concept VoidCallable = Invocable<F, Args...> &&
81 std::is_void_v<std::invoke_result_t<F, Args...>>;
82
95template<typename F, typename R, typename... Args>
96concept ReturnsResult = Invocable<F, Args...> &&
97 std::convertible_to<std::invoke_result_t<F, Args...>, R>;
98
114template<typename F, typename... Args>
115concept NoexceptCallable = Invocable<F, Args...> &&
116 std::is_nothrow_invocable_v<F, Args...>;
117
136template<typename F, typename... Args>
137concept Predicate = Invocable<F, Args...> &&
138 std::convertible_to<std::invoke_result_t<F, Args...>, bool>;
139
154template<typename F, typename Arg>
156
172template<typename F, typename Arg1, typename Arg2>
174
192template<typename T>
193concept JobLike = requires(T t) {
194 { t.execute() };
195 { t.get_name() } -> std::convertible_to<std::string>;
196 { t.get_priority() } -> std::convertible_to<int>;
197};
198
216template<typename T>
217concept ExecutorLike = requires(T t, std::unique_ptr<interfaces::IJob> job, bool wait) {
218 { t.worker_count() } -> std::convertible_to<size_t>;
219 { t.is_running() } -> std::convertible_to<bool>;
220 { t.pending_tasks() } -> std::convertible_to<size_t>;
221 { t.shutdown(wait) } -> std::same_as<void>;
222};
223
239template<typename F, typename T>
241 std::convertible_to<std::invoke_result_t<F>, std::unique_ptr<T>>;
242
255template<typename F, typename R>
257 std::same_as<std::invoke_result_t<F>, R>;
258
274template<typename F>
276 std::move_constructible<std::decay_t<F>>;
277
278} // namespace concepts
279} // namespace kcenon::common
Abstract job interface for task execution.
Definition executor.cppm:49
A callable suitable for async execution returning a future.
Definition callable.h:256
A callable type that takes two arguments.
Definition callable.h:173
A callable suitable for delayed execution.
Definition callable.h:275
A type that satisfies the Executor interface requirements.
Definition callable.h:217
A callable type that can be invoked with given arguments.
Definition callable.h:62
A type that satisfies the Job interface requirements.
Definition callable.h:193
A callable type that is marked noexcept.
Definition callable.h:115
A callable type that returns a boolean value.
Definition callable.h:137
A callable type that returns a value convertible to the specified type.
Definition callable.h:96
A callable that creates a job or task.
Definition callable.h:240
A callable type that takes a single argument.
Definition callable.h:155
A callable type that returns void when invoked.
Definition callable.h:80
Core interfaces.
Definition adapter.h:21
Consolidated core types for Result<T> pattern.