Closed svnscha closed 5 years ago
My previous attempt does not work and I totally did not think about that situation that a better enum could be in a namespace. Then the specialization does fail.
However, how about that approach?
namespace test {
BETTER_ENUM(Channel, char, Red = 1, Green, Blue)
}
BETTER_ENUMS_DECLARE_STD_HASH(test::Channel)
int main()
{
test::Channel channel = test::Channel::Red;
std::unordered_map<test::Channel, int> u = {
{test::Channel::Red, 1},
{test::Channel::Blue, 3},
};
printf("Red %d\n", u[test::Channel::Red]);
printf("Blue %d\n", u[test::Channel::Blue]);
return 0;
}
However, how about that approach?
If it works, I will merge it :)
If possible, can you add a test case that exercises this? It should probably go somewhere in this block:
However, how about that approach?
If it works, I will merge it :)
If possible, can you add a test case that exercises this? It should probably go somewhere in this block:
Do you mean by making a test case that tests the unordered_map
?
Do you mean by making a test case that tests the
unordered_map
?
Yes.
I am going to add the test case on Monday.
I have added a new runtime test @aantron as I dont know if it is really possible to make a std::hash
operator usable in a constexpr
. Would you chheck it out and see if that is how you wanted it?
A run-time test is fine. It looks like it's not compiling, though. See, e.g., https://travis-ci.org/aantron/better-enums/jobs/558780607#L1386.
Wow, finally.. @aantron ^^
:p
Thanks!
Thanks for better-enum. It is awesome. However I was missing a feature to use the enum values in _unorderedmap. I have extended it for this use case. Please review and accept my PR.