enum

64 bit enum in C++?

匿名 (未验证) 提交于 2019-12-03 01:57:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Is there a way to have a 64 bit enum in C++? Whilst refactoring some code I came across bunch of #defines which would be better as an enum, but being greater than 32 bit causes the compiler to error. For some reason I thought the following might work: enum MY_ENUM : unsigned __int64 { LARGE_VALUE = 0x1000000000000000, }; 回答1: I don't think that's possible with C++98. The underlying representation of enums is up to the compiler. In that case, you are better off using: const __int64 LARGE_VALUE = 0x1000000000000000L; As of C++11, it is

Is it possible to write a generic enum converter for JPA?

匿名 (未验证) 提交于 2019-12-03 01:57:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I wanted to write a Converter for JPA that stores any enum as UPPERCASE. Some enums we encounter do not follow yet the convention to use only Uppercase letters so until they are refactored I still store the future value. What I got so far: package student; public enum StudentState { Started, Mentoring, Repeating, STUPID, GENIUS; } I want "Started" to be stored as "STARTED" and so on. package student; import jpa.EnumUppercaseConverter; import javax.persistence.*; import java.io.Serializable; import java.util.Date; @Entity @Table(name =

OpenCV Mat element types and their sizes

匿名 (未验证) 提交于 2019-12-03 01:56:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm confused by the OpenCV Mat element types. This is from the docs: There is a limited fixed set of primitive data types the library can operate on. That is, array elements should have one of the following types: 8-bit unsigned integer (uchar) 8-bit signed integer (schar) 16-bit unsigned integer (ushort) 16-bit signed integer (short) 32-bit signed integer (int) 32-bit floating-point number (float) 64-bit floating-point number (double) ... For these basic types, the following enumeration is applied: enum { CV_8U=0, CV_8S=1, CV_16U=2, CV_16S

Enum and property naming conflicts

匿名 (未验证) 提交于 2019-12-03 01:55:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: When using a class that has an enum property, one usually gets a naming conflict between the property name and the enum type. Example: enum Day{ Monday, Tuesday, ... } class MyDateClass { private Day day; public Day Day{ get{ return day; } } } Since only flags enums should have plural names, naming the enum "Days" is not the way to go for a non-flag enum. In the above example you could use some variation like "WeekDay" for either the enum or the property. But in the general case there are no good variations like that so you end up using

How do I use custom keys with Swift 4's Decodable protocol?

匿名 (未验证) 提交于 2019-12-03 01:55:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Swift 4 introduced support for native JSON encoding and decoding via the Decodable protocol. How do I use custom keys for this? E.g., say I have a struct struct Address:Codable { var street:String var zip:String var city:String var state:String } I can encode this to JSON. let address = Address(street: "Apple Bay Street", zip: "94608", city: "Emeryville", state: "California") if let encoded = try? encoder.encode(address) { if let json = String(data: encoded, encoding: .utf8) { // Print JSON String print(json) // JSON string is { "state":

How to supply Enum value to an annotation from a Constant in Java

匿名 (未验证) 提交于 2019-12-03 01:52:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm unable to use an Enum taken from a Constant as a parameter in an annotation. I get this compilation error: "The value for annotation attribute [attribute] must be an enum constant expression". This is a simplified version of the code for the Enum: public enum MyEnum { APPLE, ORANGE } For the Annotation: @Retention(RetentionPolicy.RUNTIME) @Target({ ElementType.METHOD }) public @interface MyAnnotation { String theString(); int theInt(); MyEnum theEnum(); } And the class: public class Sample { public static final String STRING_CONSTANT =

Swift: Convert enum value to String?

匿名 (未验证) 提交于 2019-12-03 01:52:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Given the following enum: enum Audience { case Public case Friends case Private } How do I get the string "Public" from the audience constant below? let audience = Audience.Public 回答1: Not sure in which Swift version this feature was added, but right now ( Swift 2.1 ) you only need this code: enum Audience: String { case Public case Friends case Private } let audience = Audience.Public.rawValue // "Public" When strings are used for raw values, the implicit value for each case is the text of that case’s name . [...] enum CompassPoint: String

“Expected class, delegate, enum, interface or struct” error on public static string MyFunc(). What's an alternative to “string”?

匿名 (未验证) 提交于 2019-12-03 01:49:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm getting an error when I attempt to use the following static function. Error: Expected class, delegate, enum, interface, or struct Function (and class): namespace MyNamespace { public class MyClass { // Some other static methods that use Classes, delegates, enums, interfaces, or structs public static string MyFunc(string myVar){ string myText = myVar; //Do some stuff with myText and myVar return myText; } } } This is causing the compiler to angrily (in red) underline the string part of public static string . So, I assume this means string

Comparing the enum constants in thymeleaf

匿名 (未验证) 提交于 2019-12-03 01:49:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I have an enum, Constants : enum Constants { ONE , TWO , THREE ; } How can I compare the enum Constants in Thymeleaf. Thanks. 回答1: To compare with an enum constant, use the following code: th : if = "${day == T(my.package.MyEnum).MONDAY}" 回答2: One more way: th : if = "${constant.name() == 'ONE'}" It's shorter but makes compare with string representation, can cause problem while refactoring. 回答3: @Nick answer has a small syntax error, it's missing a final brace. It should be th : if = "${day == T(my.package.MyEnum).MONDAY}" 回答4: th

Swift constants: Struct or Enum

匿名 (未验证) 提交于 2019-12-03 01:49:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm not sure which of both are better to define constants. A struct or a enum. A struct will be copied every time i use it or not? When i think about a struct with static let constants it makes no sense that it will copied all the time, in my opinion. But if it won't copied then it doesn't matter what I take? What advantages does the choice of a struct or enum? Francisco say use Struct's. Ray Wunderlich say use Enum's. But I lack the justification. 回答1: Both structs and enumerations work. As an example, both struct PhysicalConstants { static