-
-
Notifications
You must be signed in to change notification settings - Fork 168
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
Traits class #21
Comments
Agreed, this would be nice. However, I don't think I can just do it in the obvious way, using template specialization: namespace better_enums {
template <typename T>
struct _is_better_enum_value {
constexpr static const bool value = false;
};
template <typename T>
struct is_better_enum : public _is_better_enum_value<T> {
// Standard members: type, value_type, operator bool, operator ().
};
} // The specialization, generated by the macro...
template <>
struct _is_better_enum_value {
constexpr static const bool value = true;
}; because the specialization does not occur, in general, in a namespace that encloses the original template declaration. So, if you do namespace my_ns {
BETTER_ENUM(Foo, int, bar)
} you will get an error, since There is probably some way to do this with SFINAE, by checking a specially-named member of generated enums. This is a bit fragile, but should be pretty easy in C++11. I am not sure if it can work in C++98, though – C++98 is a bit out of my brain's cache right now. I'm a bit overwhelmed by other work at the moment, but I will look into it later. You are welcome to comment as well :) |
@aantron I currently implemented it in my code using SFINAE checking
|
All those could work, but if implemented literally that way, they would require C++11. While I've been thinking on and off about dropping C++98 support, I think it's better to keep it for as long as reasonably possible. I'm pretty sure Deriving all enums from a base class should be fine. Adding some less collision-prone member value or type, such as |
@aantron I've only been using C++11 for the last 5 years at least, so I don't think I can help with C++98. I wonder if there's any particular reason for C++98 support? I can hardly imagine someone using it for new code nowadays :) Could it be provided as C++11-only feature? |
Yep, it can be provided as a C++11-only feature, and might have to be. I'd still like to try to adapt it to C++98 first, though, so If you don't mind the upstream not having this for a while, then let me get around to it. It's definitely on the list of things I want to add :) As for C++98, I think a lot of people are stuck in old code bases. They might still want a nicer enum :) I'm actually planning to take advantage of some C++14 features, too, when I next have the time for a burst of work on Better Enums. I may be removing C++98 at that point, if supporting all 3 standards gets too cumbersome. |
Following on #22, if MSVC has had a |
For those of use willing to use C++11 features, is there a way we can write our own macro that wraps |
Could |
You should be able to write ordinary variable-argument macros wrapping In the meantime, I'm tending towards finally dropping C++98 the next time I have hours to work on Better Enums. |
I haven't tried yet. I never had to write variable-argument macros before and just wanted to check that it was even possible before attempting it. |
+1 for deriving the types from a common base type, so I can develop functionality that works on all enum types without using templates! |
deriving the types from a common base type can help me too, I'm working on a generic object inspector and is the only way to draw a generic gui without manage every specific enum type from code |
Just a bump noting that there are more people interested in |
Noted! I really need to get around to doing this. |
I am also interested in this functionality. I see that this issue was added to 0.11.3 milestone, but 0.11.3 is already released. Does this mean that this feature has not been implemented yet? |
I would be nice to have a traits class to detect whether a type is a "better enum" (akin to
std::is_enum
)The text was updated successfully, but these errors were encountered: