enum_name
Loading...
Searching...
No Matches
meta.hpp
1/*
2MIT License
3
4Copyright (c) 2024 mguludag
5
6Permission is hereby granted, free of charge, to any person obtaining a copy
7of this software and associated documentation files (the "Software"), to deal
8in the Software without restriction, including without limitation the rights
9to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10copies of the Software, and to permit persons to whom the Software is
11furnished to do so, subject to the following conditions:
12
13The above copyright notice and this permission notice shall be included in all
14copies or substantial portions of the Software.
15
16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22SOFTWARE.
23*/
24
25#ifndef DETAIL_META_HPP
26#define DETAIL_META_HPP
27
28#include "mgutility/_common/definitions.hpp"
29#include <initializer_list>
30#include <type_traits>
31#include <utility>
32
33namespace mgutility {
34namespace detail {
35
41#ifndef MGUTILITY_ENUM_NAME_BUFFER_SIZE
42// NOLINTNEXTLINE [cppcoreguidelines-macro-usage]
43#define MGUTILITY_ENUM_NAME_BUFFER_SIZE 128U
44#endif
45
51template <typename E> struct is_scoped_enum {
55 static constexpr auto value =
56 // NOLINTNEXTLINE [modernize-type-traits]
57 std::is_enum<E>::value &&
58 // NOLINTNEXTLINE [modernize-type-traits]
59 !std::is_convertible<E, typename std::underlying_type<E>::type>::value;
60};
61
68template <typename T, typename = void> struct has_bit_or : std::false_type {};
69
76template <typename T>
77struct has_bit_or<T, decltype((T{} | T{}), void())> : std::true_type {};
78
79#if MGUTILITY_CPLUSPLUS > 201103L
85template <typename E>
86static constexpr bool is_scoped_enum_v = is_scoped_enum<E>::value;
87#endif
88
99template <bool B, class T = void>
100// NOLINTNEXTLINE [modernize-type-traits]
101using enable_if_t = typename std::enable_if<B, T>::type;
102
108template <typename T>
109// NOLINTNEXTLINE [modernize-type-traits]
110using underlying_type_t = typename std::underlying_type<T>::type;
111
117template <typename T>
118// NOLINTNEXTLINE [modernize-type-traits]
119using remove_const_t = typename std::remove_const<T>::type;
120
127template <typename Enum, Enum...> struct enum_sequence {};
128
137template <typename Enum, int Min, int Max, int... Next>
139 : enum_sequence_helper<Enum, Min, Max - 1, Max - 1, Next...> {};
140
148template <typename Enum, int Min, int... Next>
149struct enum_sequence_helper<Enum, Min, Min, Next...> {
154};
155
163template <typename Enum, int Min, int Max>
164using make_enum_sequence =
166} // namespace detail
167
173template <typename T> struct enum_range {
174 static constexpr auto min{0};
175 static constexpr auto max{256};
176};
177
178template <typename T, typename U> struct pair {
179 T first;
180 U second;
181};
182
183template <typename T>
184#if MGUTILITY_CPLUSPLUS > 201402L || defined(__GNUC__) && !defined(__clang__)
185using flat_map = std::initializer_list<pair<T, const char *>>;
186#else
187// NOLINTNEXTLINE [cppcoreguidelines-avoid-c-arrays]
189#endif
190
196template <typename T> struct custom_enum {
197 static constexpr flat_map<T> map = {};
198};
199
205template <typename T> struct enum_name_buffer {
206 static constexpr auto size = MGUTILITY_ENUM_NAME_BUFFER_SIZE;
207};
208
209} // namespace mgutility
210
211#endif // DETAIL_META_HPP
Checks for MSVC compiler version.
Definition enum_for_each.hpp:35
Provides the custom names map for an enumeration type.
Definition meta.hpp:196
Helper for generating a sequence of enumeration values.
Definition meta.hpp:139
Represents a sequence of enumeration values.
Definition meta.hpp:127
Trait to check if a type supports the bitwise OR operator.
Definition meta.hpp:68
Trait to check if a type is a scoped enumeration.
Definition meta.hpp:51
static constexpr auto value
Boolean value indicating if the type is a scoped enumeration.
Definition meta.hpp:55
Provides the name buffer size for an enumeration type.
Definition meta.hpp:205
Provides the range for an enumeration type.
Definition meta.hpp:173
Definition meta.hpp:178