Database System 0.1.0
Advanced C++20 Database System with Multi-Backend Support
Loading...
Searching...
No Matches
concepts.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
48#pragma once
49
50#include <concepts>
51#include <type_traits>
52#include <functional>
53#include <memory>
54#include <string>
55#include <future>
56
57// Forward declarations
58namespace database {
59class database_base;
60namespace core {
61class database_backend;
62// database_row is a type alias defined in database_backend.h, not forward-declarable
63} // namespace core
64} // namespace database
65
67
68// ═══════════════════════════════════════════════════════════════════════════
69// Callable Concepts (adapted from common_system for database_system)
70// ═══════════════════════════════════════════════════════════════════════════
71
76template<typename F, typename... Args>
77concept Invocable = std::invocable<F, Args...>;
78
83template<typename F, typename... Args>
84concept VoidCallable = Invocable<F, Args...> &&
85 std::is_void_v<std::invoke_result_t<F, Args...>>;
86
91template<typename F, typename R, typename... Args>
92concept ReturnsResult = Invocable<F, Args...> &&
93 std::convertible_to<std::invoke_result_t<F, Args...>, R>;
94
99template<typename F, typename... Args>
100concept Predicate = Invocable<F, Args...> &&
101 std::convertible_to<std::invoke_result_t<F, Args...>, bool>;
102
107template<typename F, typename... Args>
108concept NoexceptCallable = Invocable<F, Args...> &&
109 std::is_nothrow_invocable_v<F, Args...>;
110
115template<typename F>
117 std::move_constructible<std::decay_t<F>>;
118
123template<typename F, typename R>
125 std::same_as<std::invoke_result_t<F>, R>;
126
127// ═══════════════════════════════════════════════════════════════════════════
128// Database-Specific Callable Concepts
129// ═══════════════════════════════════════════════════════════════════════════
130
146template<typename F, typename ResultType>
148
161template<typename F>
163
176template<typename F>
178 std::convertible_to<std::invoke_result_t<F>, std::unique_ptr<database_base>>;
179
192template<typename F>
194 std::convertible_to<std::invoke_result_t<F>, std::unique_ptr<core::database_backend>>;
195
196// ═══════════════════════════════════════════════════════════════════════════
197// Event and Stream Concepts
198// ═══════════════════════════════════════════════════════════════════════════
199
212template<typename F, typename EventType>
214
227template<typename F, typename EventType>
229
230// ═══════════════════════════════════════════════════════════════════════════
231// Transaction Concepts
232// ═══════════════════════════════════════════════════════════════════════════
233
246template<typename F>
248
261template<typename F>
263
264// ═══════════════════════════════════════════════════════════════════════════
265// Pool Concepts
266// ═══════════════════════════════════════════════════════════════════════════
267
283template<typename T>
284concept PooledResource = std::is_class_v<T> &&
285 std::is_default_constructible_v<T>;
286
300template<typename T>
301concept ConnectionWrapper = requires(T t) {
302 { t.get() } -> std::convertible_to<database_base*>;
303 { t.is_valid() } -> std::convertible_to<bool>;
304};
305
306// ═══════════════════════════════════════════════════════════════════════════
307// Task Execution Concepts
308// ═══════════════════════════════════════════════════════════════════════════
309
326template<typename F, typename... Args>
327concept SubmittableTask = Invocable<F, Args...> &&
328 std::move_constructible<std::decay_t<F>>;
329
342template<typename F, typename... Args>
343concept VoidTask = VoidCallable<F, Args...> &&
344 std::move_constructible<std::decay_t<F>>;
345
346} // namespace database::concepts
A callable suitable for async execution.
Definition concepts.h:124
A callable that creates database backends.
Definition concepts.h:193
A callable that represents a compensation (rollback) action.
Definition concepts.h:262
A callable that creates database connections.
Definition concepts.h:177
A type that wraps a database connection.
Definition concepts.h:301
A callable suitable for delayed execution.
Definition concepts.h:116
A callable that handles database errors.
Definition concepts.h:162
A callable type that can be invoked with given arguments.
Definition concepts.h:77
A callable type that is marked noexcept.
Definition concepts.h:108
A type that can be managed by a pool.
Definition concepts.h:284
A callable type that returns a boolean value.
Definition concepts.h:100
A callable that handles query results.
Definition concepts.h:147
A callable type that returns a value convertible to the specified type.
Definition concepts.h:92
A callable that filters stream events.
Definition concepts.h:228
A callable that handles stream events.
Definition concepts.h:213
A callable suitable for submission to an async executor.
Definition concepts.h:327
A callable that represents a transaction action.
Definition concepts.h:247
A callable type that returns void when invoked.
Definition concepts.h:84
A callable that returns void, suitable for fire-and-forget execution.
Definition concepts.h:343