Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support gcc8 with defined MAGIC_ENUM_NO_CHECK_SUPPORT and with specialized magic_enum::customize::enum_name #137

Merged
merged 5 commits into from
Feb 18, 2022

Conversation

schaumb
Copy link
Contributor

@schaumb schaumb commented Feb 18, 2022

I tried to run examples and tests with gcc8, with manually specialized magic_enum::customize::enum_name.
I know that GCC8 is not supported, but these changes help us to make compatible our code with older GCC too only with the custom template function.


I replaced
#if defined(MAGIC_ENUM_SUPPORTED) && MAGIC_ENUM_SUPPORTED
macros to
if constexpr (supported<E>::value) {

at class name getter n(), and operator<<
These functions work with custom magic_enum::customize::enum_name, so it is enough to check supported flag.


I replaced detail::min_v<E> template parameter E, because E can be a reference, and std::underlying_type is undefined in some compilers when the template parameter is a reference.


I switched values_v and entries_v from auto to std::array, because GCC8 is not able to deduct the whole type, but std::array template parameters. This change should not change the newer compilers (and it is not a big change)

@Neargye
Copy link
Owner

Neargye commented Feb 18, 2022

detail::min_v with E
It's a good catch, there really should have been a D, it was a typo.

In general, I like the changes, I will look at them a little more before the merge.

@Neargye
Copy link
Owner

Neargye commented Feb 18, 2022

Corrected the style and made the same check for n<E, V>(). Can you check if these changes are ok for you? and I think this PR is ready

@schaumb
Copy link
Contributor Author

schaumb commented Feb 18, 2022

These changes are ok! Thanks :)

@Neargye Neargye added the enhancement New feature or request label Feb 18, 2022
@Neargye Neargye merged commit 07181c5 into Neargye:master Feb 18, 2022
@Neargye
Copy link
Owner

Neargye commented Feb 18, 2022

Thanks!

@schaumb schaumb deleted the support_gcc8_with_define branch February 18, 2022 21:38
@JuliaGut
Copy link

@schaumb I really like the Magic Enum library, but unfortunately I only have a gcc8 compiler available for my project.
Do you know, if it is possible to use the function "magic_enum::enum_name" with gcc8 compiler? If so, could you tell me which version of the library to use for it?

@schaumb
Copy link
Contributor Author

schaumb commented Oct 11, 2023

Hi @JuliaGut
So the Magic Enum lib is not supported on gcc-8, because the hack used in this lib is not available on gcc-8.

If you want to use it, you need to specify all member's names individually.
It can be done like this

enum class EN {
    asd,
    fgh
};

namespace magic_enum::customize {
template<>
constexpr customize_t enum_name<EN>(EN e) {
    switch(e) {
        case EN::asd: return "asd";
        case EN::fgh: return "fgh";
    }
    return invalid_tag;
}
}

@JuliaGut
Copy link

Thanks a lot for the quick response! 🥇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants