This commit is contained in:
Neargye 2018-09-01 22:19:33 +05:00
parent bfacde30f2
commit 3634092bf2
2 changed files with 6 additions and 6 deletions

View file

@ -385,7 +385,7 @@ template <typename T, int I = 0>
struct NameofEnumImpl {
NAMEOF_CONSTEXPR nameof::cstring operator()(T value) const {
return (static_cast<int>(value) - I == 0)
? NameofEnumImpl2<T, T(I)>()
? NameofEnumImpl2<T, T(0 + I)>()
: (static_cast<int>(value) >= 0)
? NameofEnumImpl<T, I + 1>{}(value)
: NameofEnumImpl<T, I - 1>{}(value);

View file

@ -70,7 +70,7 @@ struct Long {
enum class Color { RED = -1, GREEN, BLUE };
enum Directions { Up, Down, Right, Left};
enum Directions : int { Up, Down, Right, Left};
SomeStruct struct_var;
Long othervar;
@ -145,17 +145,17 @@ TEST_CASE("constexpr") {
REQUIRE(cx6 == "__cplusplus");
}
#if defined(NAMEOF_HAS_CONSTEXPR)
SECTION("NAMEOF_ENUM") {
constexpr auto cx = NAMEOF_ENUM(color);
#if defined(__clang__) || defined(_MSC_VER)
# if defined(__clang__) || defined(_MSC_VER)
static_assert(cx == "RED", "");
REQUIRE(cx == "RED");
#elif defined(__GNUC__)
# elif defined(__GNUC__)
REQUIRE(cx == "(const Color)-1");
#endif
# endif
}
#if defined(NAMEOF_TYPE_HAS_CONSTEXPR)
SECTION("NAMEOF_TYPE") {
constexpr auto cx = NAMEOF_TYPE(ptr_c);
# if defined(__clang__)