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
29#include <initializer_list>
30#include <type_traits>
31#include <utility>
32
33namespace mgutility {
34namespace detail {
40template <typename E> struct is_scoped_enum {
44 static constexpr auto value =
45 std::is_enum<E>::value &&
46 !std::is_convertible<E, typename std::underlying_type<E>::type>::value;
47};
48
55template <typename T, typename = void> struct has_bit_or : std::false_type {};
56
63template <typename T>
64struct has_bit_or<T, decltype((T{} | T{}), void())> : std::true_type {};
65
66#if MGUTILITY_CPLUSPLUS > 201103L
72template <typename E>
73static constexpr bool is_scoped_enum_v = is_scoped_enum<E>::value;
74#endif
75
86template <bool B, class T = void>
87using enable_if_t = typename std::enable_if<B, T>::type;
88
94template <typename T>
95using underlying_type_t = typename std::underlying_type<T>::type;
96
102template <typename T>
103using remove_const_t = typename std::remove_const<T>::type;
104
111template <typename Enum, Enum...> struct enum_sequence {};
112
121template <typename Enum, int Min, int Max, int... Next>
123 : enum_sequence_helper<Enum, Min, Max - 1, Max - 1, Next...> {};
124
132template <typename Enum, int Min, int... Next>
139
147template <typename Enum, int Min, int Max>
148using make_enum_sequence = typename enum_sequence_helper<Enum, Min, Max>::type;
149} // namespace detail
150
156template <typename T> struct enum_range {
157 static constexpr auto min{0};
158 static constexpr auto max{256};
159};
160
161template <typename T, typename U> struct pair {
162 T first;
163 U second;
164};
165
166template <typename T>
167#if MGUTILITY_CPLUSPLUS > 201103L || defined(__GNUC__) && !defined(__clang__)
168using flat_map = std::initializer_list<pair<T, const char *>>;
169#else
171#endif
172
178template <typename T> struct custom_enum {
179 static constexpr flat_map<T> map = {};
180};
181} // namespace mgutility
182
183#endif // DETAIL_META_HPP
Defines macros for compiler and standard support detection.
Checks for MSVC compiler version.
Definition enum_for_each.hpp:34
Provides the custom names map for an enumeration type.
Definition meta.hpp:178
Helper for generating a sequence of enumeration values.
Definition meta.hpp:123
Represents a sequence of enumeration values.
Definition meta.hpp:111
Trait to check if a type supports the bitwise OR operator.
Definition meta.hpp:55
Trait to check if a type is a scoped enumeration.
Definition meta.hpp:40
static constexpr auto value
Boolean value indicating if the type is a scoped enumeration.
Definition meta.hpp:44
Provides the range for an enumeration type.
Definition meta.hpp:156
Definition meta.hpp:161