StormByte 3.0.0
C++26 foundation of the StormByte suite
Loading...
Searching...
No Matches
wrappers.hxx
Go to the documentation of this file.
1/*
2 * Copyright (C) 2024-2026 David C. Manuelda (StormBytePP)
3 *
4 * This is the base for StormByte Suite libraries.
5 *
6 * StormByte original source is dual-licensed:
7 *
8 * 1. GNU Lesser General Public License v3.0 (or later)
9 * You may redistribute and/or modify this file under the terms of the
10 * GNU Lesser General Public License as published by the Free Software
11 * Foundation, either version 3 of the License, or (at your option)
12 * any later version.
13 *
14 * 2. Commercial license
15 * Alternatively, this file may be used under the terms of a commercial
16 * license agreement with the copyright holder
17 * (David C. Manuelda <StormByte@gmail.com>).
18 *
19 * Both licenses apply only to original StormByte source in this repository.
20 * They do not cover other StormByte modules or any third-party material
21 * shipped with this repository (including everything under thirdparty/),
22 * which remains under its own license.
23 *
24 * Neither license grants any patent rights. Any patent licenses required
25 * to use this software or third-party components must be obtained separately
26 * from the patent holders.
27 *
28 * StormByte is distributed in the hope that it will be useful,
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 * GNU Lesser General Public License for more details.
32 *
33 * You should have received a copy of the GNU Lesser General Public License
34 * version 3 along with StormByte. If not, see
35 * <https://www.gnu.org/licenses/lgpl-3.0.html>.
36 *
37 * SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-StormByte-Commercial
38 */
39
40#pragma once
41
43
44#include <concepts>
45#include <cstddef>
46#include <optional>
47#include <queue>
48#include <type_traits>
49#include <utility>
50#include <variant>
51
56namespace StormByte {
61 namespace Type {
66 namespace Detail {
74 template<typename T>
75 constexpr bool is_variant_v = false;
76
81 template<typename... Ts>
82 constexpr bool is_variant_v<std::variant<Ts...>> = true;
83
88 template<typename T>
89 struct is_std_queue: std::false_type {};
90
96 template<typename Value, typename Container>
97 struct is_std_queue<std::queue<Value, Container>>: std::true_type {};
98
107 template<typename VariantT, typename U, std::size_t... I>
108 constexpr bool variant_has_type_impl(std::index_sequence<I...> seq) noexcept {
109 (void)seq;
110 return ((std::is_same_v<
111 std::remove_cvref_t<U>,
112 std::remove_cvref_t<std::variant_alternative_t<I, VariantT>>
113 >) || ...);
114 }
115
121 template<typename VariantT, typename U>
122 constexpr bool variant_has_type_v =
124 std::make_index_sequence<std::variant_size_v<VariantT>>()
125 );
126 }
127
133
138
151 template<typename T>
152 concept Optional =
153 (requires { typename T::value_type; } &&
154 std::same_as<T, std::optional<typename T::value_type>>) || IsSafeOptional<T>::value;
155
163 template<typename T>
164 concept Queue =
166
176 template<typename T>
178
190 template<typename T, typename U>
192 Variant<T> &&
194
196
201
214 template<typename T>
215 concept Pair = requires(T t) {
216 t.first;
217 t.second;
218 };
219
222 }
223}
std::optional<U> or a Safe optional wrapper.
Definition wrappers.hxx:152
Type with accessible first and second members.
Definition wrappers.hxx:215
FIFO wrappers supported by generic queue operations.
Definition wrappers.hxx:164
StormByte::Type::Variant T that lists U among its alternatives.
Definition wrappers.hxx:191
Instantiation of std::variant, after stripping cv and references.
Definition wrappers.hxx:177
Private helpers for Safe classification.
Definition containers.hxx:121
constexpr bool variant_has_type_impl(std::index_sequence< I... > seq) noexcept
Fold: is stripped U one of VariantT's alternatives?
Definition wrappers.hxx:108
constexpr bool variant_has_type_v
Convenience wrapper around StormByte::Type::Detail::variant_has_type_impl.
Definition wrappers.hxx:122
constexpr bool is_variant_v
true when T is exactly std::variant after stripping cv and references.
Definition wrappers.hxx:75
Named concepts and small type utilities used across the suite.
Root namespace of the StormByte suite.
STL namespace.
Primary classification for standard FIFO wrappers.
Definition wrappers.hxx:89
Identifies Safe optional wrappers.
Definition safe.hxx:329
Identifies Safe FIFO wrappers.
Definition safe.hxx:337