enums

Check if an enum contains more than one flag [duplicate]

此生再无相见时 提交于 2021-01-03 22:12:33
问题 This question already has answers here : How do I check if more than one enum flag is set? (5 answers) Test that only a single bit is set in Flags Enum [duplicate] (1 answer) Closed 29 days ago . I am trying to check if an "enum instance" contains more than one flag. [Flags] public enum Foo { Bar = 1, Far = 2 } var multiState = Foo.Bar | Foo.Far; MoreThanOneFlag(multiState); // True var singleState = Foo.Bar; MoreThanOneFlag(singleState); // False Additionally I really don't wanna use

Check if an enum contains more than one flag [duplicate]

邮差的信 提交于 2021-01-03 22:10:27
问题 This question already has answers here : How do I check if more than one enum flag is set? (5 answers) Test that only a single bit is set in Flags Enum [duplicate] (1 answer) Closed 29 days ago . I am trying to check if an "enum instance" contains more than one flag. [Flags] public enum Foo { Bar = 1, Far = 2 } var multiState = Foo.Bar | Foo.Far; MoreThanOneFlag(multiState); // True var singleState = Foo.Bar; MoreThanOneFlag(singleState); // False Additionally I really don't wanna use

Enums support for inheritance

笑着哭i 提交于 2020-12-31 06:09:42
问题 I frequently come across a situation where we create a class that acts on some enumeration, but later we derive and we want to add more values to the enumeration without changing the base class. I see this question from 2009: Base enum class inheritance However, I know there were a number of changes to enum in C++11, 14, 17. Do any of those changes allow for extension of enums from base class to derived? class Base { enum State {STATE_1, STATE_2, STATE_3}; }; class Derived : public Base {

Enums support for inheritance

跟風遠走 提交于 2020-12-31 06:09:34
问题 I frequently come across a situation where we create a class that acts on some enumeration, but later we derive and we want to add more values to the enumeration without changing the base class. I see this question from 2009: Base enum class inheritance However, I know there were a number of changes to enum in C++11, 14, 17. Do any of those changes allow for extension of enums from base class to derived? class Base { enum State {STATE_1, STATE_2, STATE_3}; }; class Derived : public Base {

Enums support for inheritance

痞子三分冷 提交于 2020-12-31 06:05:27
问题 I frequently come across a situation where we create a class that acts on some enumeration, but later we derive and we want to add more values to the enumeration without changing the base class. I see this question from 2009: Base enum class inheritance However, I know there were a number of changes to enum in C++11, 14, 17. Do any of those changes allow for extension of enums from base class to derived? class Base { enum State {STATE_1, STATE_2, STATE_3}; }; class Derived : public Base {

Enums support for inheritance

安稳与你 提交于 2020-12-31 06:04:11
问题 I frequently come across a situation where we create a class that acts on some enumeration, but later we derive and we want to add more values to the enumeration without changing the base class. I see this question from 2009: Base enum class inheritance However, I know there were a number of changes to enum in C++11, 14, 17. Do any of those changes allow for extension of enums from base class to derived? class Base { enum State {STATE_1, STATE_2, STATE_3}; }; class Derived : public Base {

Selecting enum values based on key names

拟墨画扇 提交于 2020-12-29 12:15:03
问题 I have an enum like so: public enum Animals { CatOne = 12, CatTwo = 13, CatThree = 14, DogOne = 21, DogTwo = 22 }; Great. Now I want to get the values of all the cats.. What I'm trying to do is this: public static int[] GetCatValues() { List<int> catValues = new List<int>(); foreach(var cat in Enum.GetNames(typeof(Animals))) { Animals animal; if(cat.StartsWith("Cat")) { Enum.TryParse(cat, out animal); catValues.Add((int)animal); } } return catValues.ToArray(); } Which works okay. Except it

Selecting enum values based on key names

不羁的心 提交于 2020-12-29 12:09:53
问题 I have an enum like so: public enum Animals { CatOne = 12, CatTwo = 13, CatThree = 14, DogOne = 21, DogTwo = 22 }; Great. Now I want to get the values of all the cats.. What I'm trying to do is this: public static int[] GetCatValues() { List<int> catValues = new List<int>(); foreach(var cat in Enum.GetNames(typeof(Animals))) { Animals animal; if(cat.StartsWith("Cat")) { Enum.TryParse(cat, out animal); catValues.Add((int)animal); } } return catValues.ToArray(); } Which works okay. Except it

Store enum MongoDB

孤街醉人 提交于 2020-12-29 02:40:57
问题 I am storing enums for things such as ranks (administrator, moderator, user...) and achievements for each user in my Mongo database. As far as I know Mongo does not have an enum data type which means I have to store it using another type. I have thought of storing it using integers which I would assume uses less space than storing strings for everything that could easily be expressed as an integer. Another upside I see of using integers is that if I wanted to rename an achievement or rank I

Store enum MongoDB

匆匆过客 提交于 2020-12-29 02:39:28
问题 I am storing enums for things such as ranks (administrator, moderator, user...) and achievements for each user in my Mongo database. As far as I know Mongo does not have an enum data type which means I have to store it using another type. I have thought of storing it using integers which I would assume uses less space than storing strings for everything that could easily be expressed as an integer. Another upside I see of using integers is that if I wanted to rename an achievement or rank I