-
Notifications
You must be signed in to change notification settings - Fork 27
Open
Description
The conversion between enum and string doesn't seem to work using Visual Studio. The reason is that the preprocessor behaves incorrectly, so the string for an enum value becomes "WISE_ENUM_IMPL_IIF_1 (WISE_ENUM_IMPL_FIRST_ARG (SomeEnumValue, 0), (SomeEnumValue, 0))" instead of "SomeEnumValue".
This can be solved by enabling the new conforming preprocessor. wise_enum could check this at compile-time:
#ifdef _MSC_VER
#ifdef _MSVC_TRADITIONAL
#if _MSVC_TRADITIONAL
#error "The traditional, non-standard preprocessor is not supported. From Visual Studio 15.8 through 16.4, add the '/experimental:preprocessor' compiler option. From Visual Studio 16.5 onwards, add the '/Zc:preprocessor' compiler option."
#endif
#else
// _MSVC_TRADITIONAL is not defined, check from_string/to_string using a test enum:
namespace detail {
enum class TestEnum { SomeTestValue };
}
static_assert(detail::strcmp(to_string(detail::TestEnum::SomeTestValue), "SomeTestValue") == 0
&& from_string<detail::TestEnum>("SomeTestValue") == detail::TestEnum::SomeTestValue,
"The traditional, non-standard preprocessor is not supported. From Visual Studio 15.8 through 16.4, add the '/experimental:preprocessor' compiler option. From Visual Studio 16.5 onwards, add the '/Zc:preprocessor' compiler option.");
#endif // _MSVC_TRADITIONAL
#endif // _MSC_VERThe static_assert is a fallback for Visual Studio < 15.8, where _MSVC_TRADITIONAL isn't defined at all.
I thought I'd share this, in case someone else runs into it. This info could also be added to the README.
Metadata
Metadata
Assignees
Labels
No labels