Is it possible with a ONE-Liner (else the normal way…) to check if any of all possible enum states are set?
From enum fruits I want to know wether it is unset means no banana, no apple, no melon.
How can I do that?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Would:
myFlags == 0Suffice? 0 represents no bits set, assuming you are using flags and not doing anything funky with the values.
Given this enum:
And this code:
It does what you’d expect it to, however it is checking the underling value not doing bitwise ops, so if you mutate the underling value incorrectly you start to get issues, but you’ll get other issues as well.
Given:
And:
Also behaves.