StormByte C++ Library 1.2.0
StormByte is a comprehensive, cross-platform C++ library aimed at easing system programming, configuration management, logging, and database handling tasks. This library provides a unified API that abstracts away the complexities and inconsistencies of different platforms (Windows, Linux).
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 file is part of StormByte.
5 *
6 * StormByte is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License version 3
8 * or later, as published by the Free Software Foundation.
9 *
10 * StormByte is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with StormByte. If not, see
17 * <https://www.gnu.org/licenses/lgpl-3.0.html>.
18 */
19
20#pragma once
21
22#include <concepts>
23#include <cstddef>
24#include <optional>
25#include <type_traits>
26#include <utility>
27#include <variant>
28
33namespace StormByte {
34 namespace Type {
35 namespace Detail {
43 template<typename T>
44 constexpr bool is_variant_v = false;
45
50 template<typename... Ts>
51 constexpr bool is_variant_v<std::variant<Ts...>> = true;
52
61 template<typename VariantT, typename U, std::size_t... I>
62 constexpr bool variant_has_type_impl(std::index_sequence<I...> seq) noexcept {
63 (void)seq;
64 return ((std::is_same_v<
65 std::remove_cvref_t<U>,
66 std::remove_cvref_t<std::variant_alternative_t<I, VariantT>>
67 >) || ...);
68 }
69
75 template<typename VariantT, typename U>
76 constexpr bool variant_has_type_v =
77 variant_has_type_impl<VariantT, U>(
78 std::make_index_sequence<std::variant_size_v<VariantT>>()
79 );
80 }
81
99 template<typename T>
100 concept Optional =
101 requires { typename T::value_type; } &&
102 std::same_as<T, std::optional<typename T::value_type>>;
103
116 template<typename T>
117 concept Pair = requires(T t) {
118 t.first;
119 t.second;
120 };
121
131 template<typename T>
132 concept Variant = Detail::is_variant_v<std::remove_cvref_t<T>>;
133
145 template<typename T, typename U>
147 Variant<T> &&
148 Detail::variant_has_type_v<std::remove_cvref_t<T>, U>;
150 }
151}
Exactly std::optional<U> for some U.
Definition wrappers.hxx:100
Type with accessible first and second members.
Definition wrappers.hxx:117
Variant T that lists U among its alternatives.
Definition wrappers.hxx:146
Instantiation of std::variant, after stripping cv/ref.
Definition wrappers.hxx:132
constexpr bool variant_has_type_impl(std::index_sequence< I... > seq) noexcept
Fold: is cv/ref-stripped U one of VariantT's alternatives?
Definition wrappers.hxx:62
constexpr bool variant_has_type_v
Convenience wrapper around variant_has_type_impl.
Definition wrappers.hxx:76
constexpr bool is_variant_v
true when T is exactly std::variant<Ts...> after cv/ref strip.
Definition wrappers.hxx:44
Root namespace of the StormByte suite.