22,859 questions
- Bountied 0
- Unanswered
- Frequent
- Score
- Trending
- Week
- Month
- Unanswered (my tags)
4
votes
2
answers
152
views
How to optimize enum size?
I'm building a small regex VM that matches text with bytecode-like instructions. Take the following enum:
pub type Pc = usize;
pub enum Inst {
Char(char, Pc),
Range(char, char, Pc),
Any(...
5
votes
1
answer
186
views
MISRA C:2012 violations with enums in C99
I'm working on a C99 project that is required to follow the MISRA C:2012 standard.
Whenever I use an enumeration type, I get a violation of rule 10.4 or 10.5.
As a static analysis tool, I use the code ...
1
vote
0
answers
59
views
enum class value definition from prior values [duplicate]
According to cppreference, it is allowed to define an unscoped enum value by using prior values of the same enum, e.g. like this:
enum MyEnum_U {
u_foo = 2,
u_bar = 5,
u_baz = u_foo + ...
1
vote
2
answers
90
views
How to define an alias value for an enum member?
In Python, an enum member carries an underlying value, which can be obtained by reading the value attribute. Conversely, an enum member can be obtained from its value by calling the enum type.
class ...
15
votes
1
answer
751
views
std::equal_to<void>{}(A1, B1) does not compile, while A1 == B1 compiles in C++26 for unscoped enums?
I noticed a discrepancy between C++23 and C++26 code when using googlemock:
enum A { A1, A2 };
enum B { B1, B2 };
TEST(...)
{
ASSERT_EQ(A1, B1); // compiles fine in C++23 and C++26
ASSERT_THAT(...
1
vote
6
answers
276
views
Why do we need abstract methods in Enums
I've been studying Java for some time now to better understand what goes on inside some of the code parts.
While studying Enum, which I am used to using exclusively for listing various fixed values (...
Advice
0
votes
0
replies
26
views
Is it possible to generate string fields and const classes from nullable open enums in an OpenAPI spec?
I'm trying to generate a C# client from the OpenRouter OpenAPI spec:
https://github.com/OpenRouterTeam/typescript-sdk/blob/main/.speakeasy/in.openapi.yaml
Among other things there are some enums ...
1
vote
0
answers
62
views
EF Core + Npgsql: "column 'status' is of type application_status but expression is of type text"
I've been struggling for two days with a PostgreSQL enum type issue in Entity Framework Core. Despite all my configuration, EF Core keeps trying to send a string (`text`) to an enum column.
The ...
1
vote
1
answer
118
views
Avoid boxing of generic enum type
Given the base class:
public abstract class EnumType<TEnum, TValue>
where TEnum : struct, IConvertible
where TValue : struct
{
public abstract TEnum GetEnumValue(TValue value);
}
...
2
votes
3
answers
194
views
Can enum values be redeclared?
The C++ Coding guidelines, Enum.3: Prefer class enums over "plain" enums contains following example:
void Print_color(int color);
enum Web_color { red = 0xFF0000, green = 0x00FF00, blue = 0x0000FF };
...
0
votes
2
answers
159
views
Any Clang diagnostic flag for preventing casting an invalid int value to an enum in C?
Clang's -Wassign-enum diagnostic flag will trigger a warning when using an int whose value is out of scope of an enum's cases:
typedef enum Foo {
FooA,
FooB,
} Foo;
void handleFoo(Foo foo);
...
an0's user avatar
- 17.6k
0
votes
1
answer
132
views
Android: Filter CardViews in RecyclerView List with Room DAO
I have a RecylcerView List of CardViews. Each CardView holds user data that is saved in a Room database. Some of the CardViews have due dates that have been entered by the user with a TimePicker. I ...
1
vote
0
answers
52
views
Static typing for an `Enum` that contains compiled regex patterns
I am in a scenario (that could be compared to writing an AST) where I compile multiple regex patterns that I want to reuse later, and for the sake of simplicity and readability I want to store them in ...
0
votes
0
answers
46
views
Retrieve Oat++ ENUM documentation programmatically
I have an ENUM with some documentation about the values ("Description 1", "Description 2"):
ENUM(MyEnum, v_int32,
VALUE(VAL1, 3, "ME_VAL1", "Description 1"),...
2
votes
2
answers
183
views
Niche optimization: why is `size_of::<Result<bool, bool>>()` 2 instead of 1?
Niche optimization allows Rust to store data in the invalid bit patterns of a type. The only valid values of a bool are 0 and 1 (one bit). And Result only has two variants (one bit). So why does ...