enum-class

C++11 enum class instantiation

只愿长相守 提交于 2019-12-23 12:34:14
问题 I've encountered the following form of enum class variable instantiation and it is compiling without any warning or error under VS2012: UINT32 id; enum class X {apple, pear, orange}; X myX = X(id); Moreover, sending X(id) as an argument to a function expecting X type param compiled as well. I'm not sure if the result is always correct or it's just a strange compiler behavior. However, trying to do X myX(id); instead of the above resulted in compilation error: error C2440: 'initializing' :

How to get enum from boost::property_tree?

情到浓时终转凉″ 提交于 2019-12-19 09:06:40
问题 How do I get an enum from a boost::property_tree ? This is my "non-working" example. config.xml <root> <fooEnum>EMISSION::EMIT1</fooEnum> <fooDouble>42</fooDouble> </root> main.cpp #include <iostream> #include <boost/property_tree/ptree.hpp> #include <boost/property_tree/xml_parser.hpp> int main() { enum class EMISSION { EMIT1, EMIT2 } ; enum EMISSION myEmission; //Initialize the XML file into property_tree boost::property_tree::ptree pt; read_xml("config.xml", pt); //test enum (SUCCESS)

C++11 enum with class members and constexpr link-time optimization

…衆ロ難τιáo~ 提交于 2019-12-18 08:35:46
问题 In my project I have a lot of enumerations that need to have additional attributes associated with the enumeration members and auxiliary static methods associated with the enumeration type. As much as I know, this is not possible to have with the standard enum class MyItem {...}, so for each enum class in my project I have an auxiliary class MyItemEnum that encapsulates these auxiliary static methods and also instantiates auxiliary instances of itself, so that I can access their methods in

C++11 enum with class members and constexpr link-time optimization

╄→гoц情女王★ 提交于 2019-12-18 08:34:20
问题 In my project I have a lot of enumerations that need to have additional attributes associated with the enumeration members and auxiliary static methods associated with the enumeration type. As much as I know, this is not possible to have with the standard enum class MyItem {...}, so for each enum class in my project I have an auxiliary class MyItemEnum that encapsulates these auxiliary static methods and also instantiates auxiliary instances of itself, so that I can access their methods in

C++11 enum with class members and constexpr link-time optimization

梦想与她 提交于 2019-12-18 08:34:13
问题 In my project I have a lot of enumerations that need to have additional attributes associated with the enumeration members and auxiliary static methods associated with the enumeration type. As much as I know, this is not possible to have with the standard enum class MyItem {...}, so for each enum class in my project I have an auxiliary class MyItemEnum that encapsulates these auxiliary static methods and also instantiates auxiliary instances of itself, so that I can access their methods in

How to Enable C++11 Features in Codelite

我的梦境 提交于 2019-12-14 03:42:10
问题 The following code compiles and runs in Xcode 5 and in Visual Studio 2013. I am interested in trying out Codelite, but Codelite will not compile the following program (a problem since I am working with scoped enums in my project). As far as I understand it, Codelite is using the same compiler as Xcode. Is the code valid per C++11? Why is Codelite unable to compile it? #include <iostream> namespace abc { namespace xyz { enum class SampleEnum { SomeValue = 0, SomeOtherValue = 1 }; } } int main

Sequence of enumerators at compile time

你。 提交于 2019-12-13 05:05:20
问题 Given a C++11 enum class, is there some templating or other construct to iterate, at compile-time, over the set of all enumerators? Could one define a template to e.g. initialize an array with all possible values of that enum type? 回答1: One alternative technique is to resort to the pre-processor. #define ITERATE_MY_ENUM(_) \ _(A,) \ _(B, =3) \ _(C,) \ _(D, =10) enum MyEnum { #define DEFINE_ENUM_VALUE(key, value) key value, ITERATE_MY_ENUM(DEFINE_ENUM_VALUE) #undef DEFINE_ENUM_VALUE }; void

declaring the underlying type of enumeration identifier [closed]

ⅰ亾dé卋堺 提交于 2019-12-12 07:00:42
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . I have declared an enum as follows: enum fileType {typeA, typeB}; This is causing an error when I try to append directoryType type to

What is happening when calling an enum/enum class with parentheses in C++?

为君一笑 提交于 2019-12-11 03:46:28
问题 This is maybe a bit weird question, but I really don't know how to phrase it better than this. I just discovered that I can do the following: #include <iostream> enum class Colour // also works with plain old enum { Red = 1, Green, Blue, Yellow, Black, White }; int main() { Colour c = Colour(15); // this is the line I don't quite understand std::cout << static_cast<int>(c) << std::endl; // this returns 15 return 0; } So now I have integer value 15 in a variable of the type Colour . What

validate integer is some enum class item (C++11)

夙愿已清 提交于 2019-12-08 17:39:45
问题 i have some enum class enum class Foo { A=1, B=18 , Z=42 }; i want to check if some integer can be converted into a Foo . What would be the ideal way to do this? this is for runtime check (the integer is not known yet at compile-time) Obviously i can do this the hard way (write a function bool CheckEnum(Foo); with a big-ass switch returning true for all cases except the default one), but i was hoping a more elegant mechanism that avoided so much writing. MPL or Boost.Preprocessor would be a