aantron / better-enums

C++ compile-time enum to string, iteration, in a single header file
http://aantron.github.io/better-enums
BSD 2-Clause "Simplified" License
1.65k stars 172 forks source link

Compare the enum class with enumerated values #39

Open Auliyaa opened 7 years ago

Auliyaa commented 7 years ago

Hi,

I've been playing around with better enums recently and I was trying to compare between the enum class and its enumerated values:

auto a = Hello::World;
if (a == Hello::World)
...

As stated in some other issues, this triggers a compilation error. I dug inside the enum.h file and foudn a way to patch macro definitions to include support for such comparison cases.

However, I'm not entirely sure this patch fits well with the rest of the library, I've been testing it against my own use cases and it seems to do the job for me.

Are you interested in a patch proposal ? If so, should I create a branch directly on your repository or do you prefer a diff file attached to this ticket ?

Regards.

aantron commented 7 years ago

Hi, thanks for looking at it. Perhaps you already have done this, but you should first run the repo's tests by cloning it, and running make -C test in the repo root.

IIRC some of the other issues relating to this have discussions about why Better Enums doesn't implement nice == – make sure you don't hit the same snags.

After that, I think the typical way is to do a GitHub fork of this repo, turn your diff into a branch in that fork, and open a GitHub pull request from the fork to this repo. Opening a pull request will trigger the automated testing in Travis and AppVeyor that is set up on this repo.

gamante91 commented 1 year ago

Hi, I know this is an old thread but I have encountered the same issues and submitted the following pull request that adds operators == and != to do comparisons between enumerated values and enum classes.