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
enums.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// UnsignedEnum reuses Unsigned on the enum's underlying type.
24
25#include <type_traits>
26
31namespace StormByte {
32 namespace Type {
48 template<typename E>
49 concept Enum = std::is_enum_v<std::remove_cv_t<E>>;
50
60 template<typename E>
61 concept UnsignedEnum =
62 Enum<E> &&
64
74 template<typename E>
75 concept ScopedEnum = std::is_scoped_enum_v<E>;
76
86 template<typename E>
87 requires Enum<E>
88 using UnderlyingType = std::underlying_type_t<std::remove_cv_t<E>>;
89
101 template<typename E>
102 requires Enum<E>
103 constexpr UnderlyingType<E> ToUnderlying(E e) noexcept {
104 return static_cast<UnderlyingType<E>>(e);
105 }
107 }
108}
Unscoped or scoped enumeration (enum / enum class).
Definition enums.hxx:49
Scoped enumeration (enum class / enum struct).
Definition enums.hxx:75
Enum whose underlying type is unsigned.
Definition enums.hxx:61
Unsigned arithmetic type (std::is_unsigned).
Definition categories.hxx:189
constexpr UnderlyingType< E > ToUnderlying(E e) noexcept
Converts an enumeration value to its underlying integer.
Definition enums.hxx:103
std::underlying_type_t< std::remove_cv_t< E > > UnderlyingType
Underlying integer type of enumeration E.
Definition enums.hxx:88
Root namespace of the StormByte suite.