-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Including fmt/ranges.h and magic_enum/magic_enum_format.hpp fails to compile #4168
Comments
Including |
Understood, thank you. I understand that this is generally not considered best practice; however, there are several hundred enums I'd like to be able to print using {fmt}, and creating an individual format() definition for each is less than desirable. Is there a way to scope the specialization to all enums in a certain namespace or set of namespaces? Or is there some other alternative specialization that won't collide with the specializations in fmt? For context: I'm trying to migrate from v9.1.0 to v.11.0.2, but the removal of the default enum specialization makes this somewhat more difficult. Adding a |
You can make all enums in your namespace formattable with a generic |
Thanks, but unfortunately I cannot figure out how to get the template args for the generic |
Your usage of |
Much appreciated, thank you! |
For multiple or nested namespaces: is the recommended method of reusing the format_as() function just to define it in a separate header, then include it within each namespace? |
I would recommend injecting names in the desired namespace with using declarations (https://en.cppreference.com/w/cpp/language/using_declaration) instead of having an |
(Copying from Neargye/magic_enum#379 for visibility; I suspect it's an issue with magic_enum's templating, but wanted to ensure it's not an issue with fmt.)
magic_enum provides the following template specialization to enable serialization of enums:
Unfortunately, while this specialization works fine on its own, including
ranges.h
breaks this specalization with a compile error.magic_enum requires enum implementation and valid max and min.
(even though the default max and min should be sufficient, and it compiles fine as long asfmt/ranges.h
isn't included)#include <fmt/ranges.h>
and#include <magic_enum/magic_enum_format.hpp>
, I get a compiler error.#include <fmt/ranges.h>
allows it to compile#include <magic_enum/magic_enum_format.hpp>
also allows it to compileI suspected this may have been a issue like #4058. However, adding a specialization to opt it out of range formatting didn't work either, and I got the same compiler error.
Any guesses as to what we might be doing wrong?
The text was updated successfully, but these errors were encountered: