1313#define MEOJSON_ENUM_REFLECTION_MAX_ENUMS 128
1414#endif
1515
16+ #define MEOJSON_ENUM_RANGE (min_enum, max_enum ) _MEOJSON_ENUM_MIN = min_enum, _MEOJSON_ENUM_MAX = max_enum
17+
1618namespace json
1719{
1820namespace _reflection
@@ -21,6 +23,7 @@ template <typename E, E V>
2123constexpr std::string_view name () noexcept
2224{
2325#if defined(__clang__) || defined(__GNUG__)
26+
2427 std::string_view name = __PRETTY_FUNCTION__;
2528 auto start = name.find (" V = " );
2629 if (start == std::string_view::npos) {
@@ -41,7 +44,9 @@ constexpr std::string_view name() noexcept
4144 name = name.substr (sep + 1 );
4245 }
4346 return name;
47+
4448#elif defined(_MSC_VER)
49+
4550 std::string_view name = __FUNCSIG__;
4651 auto start = name.find (' ,' );
4752 if (start == std::string_view::npos) {
@@ -64,8 +69,11 @@ constexpr std::string_view name() noexcept
6469 name = name.substr (sep + 1 );
6570 }
6671 return name;
72+
6773#else
74+
6875 return {};
76+
6977#endif
7078}
7179
@@ -102,11 +110,55 @@ constexpr bool is_valid() noexcept
102110 return true ;
103111}
104112
113+ // 检测枚举类型是否存在 _MEOJSON_ENUM_MIN
114+ template <typename E, typename = void >
115+ struct has_enum_min : std::false_type
116+ {};
117+
118+ template <typename E>
119+ struct has_enum_min <E, std::void_t <decltype (E::_MEOJSON_ENUM_MIN)>> : std::true_type
120+ {};
121+
122+ // 检测枚举类型是否存在 _MEOJSON_ENUM_MAX
123+ template <typename E, typename = void >
124+ struct has_enum_max : std::false_type
125+ {};
126+
127+ template <typename E>
128+ struct has_enum_max <E, std::void_t <decltype (E::_MEOJSON_ENUM_MAX)>> : std::true_type
129+ {};
130+
131+ // 获取枚举最小值
132+ template <typename E, bool = has_enum_min<E>::value>
133+ struct get_enum_min
134+ {
135+ static constexpr int value = MEOJSON_ENUM_REFLECTION_MIN_ENUMS ;
136+ };
137+
138+ template <typename E>
139+ struct get_enum_min <E, true >
140+ {
141+ static constexpr int value = static_cast <int >(E::_MEOJSON_ENUM_MIN);
142+ };
143+
144+ // 获取枚举最大值
145+ template <typename E, bool = has_enum_max<E>::value>
146+ struct get_enum_max
147+ {
148+ static constexpr int value = MEOJSON_ENUM_REFLECTION_MAX_ENUMS ;
149+ };
150+
151+ template <typename E>
152+ struct get_enum_max <E, true >
153+ {
154+ static constexpr int value = static_cast <int >(E::_MEOJSON_ENUM_MAX);
155+ };
156+
105157template <typename E>
106158struct enum_range
107159{
108- static constexpr int min = MEOJSON_ENUM_REFLECTION_MIN_ENUMS ;
109- static constexpr int max = MEOJSON_ENUM_REFLECTION_MAX_ENUMS ;
160+ static constexpr int min = get_enum_min<E>::value ;
161+ static constexpr int max = get_enum_max<E>::value ;
110162};
111163
112164template <typename E, int ... Is>
0 commit comments