Skip to main content
Filter by
Sorted by
Tagged with
2 votes
3 answers
179 views

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 }; ...
Erik Man's user avatar
  • 874
4 votes
1 answer
146 views

Is there a way to automatically (and at compile time) define a "product enum class" (i.e. an enum class that takes on values in the product space between two given enum classes)? So if I ...
Taylor's user avatar
  • 2,157
29 votes
1 answer
2k views

The std::align_val_t type is defined as: namespace std { enum class align_val_t : size_t { }; } What is the purpose of such an empty enumeration? What's the difference with a typedef?
Oodini's user avatar
  • 1,463
1 vote
1 answer
62 views

template <typename FruitEnum> struct FruitManager { FruitEnum group }; enum class FirstFruitEnum { apple_fruit, banana_fruit, }; enum class SecondFruitEnum { banana_fruit, ...
Heath Barz's user avatar
-1 votes
2 answers
71 views

I have an enum class, say enum class color { Red, Green, Blue, /* etc. */}; and I have class template, template <color Color> class foo; Now, I want to declare a data type which holds, for ...
einpoklum's user avatar
  • 137k
-2 votes
2 answers
201 views

how to know an enum class is sorted, for example: // is sorted: enum class data { type1 = 2, type2 = 3, type3 = 4, type4 = 5, type5 = 6 }; // not sorted: enum class data { ...
lingfeng kong's user avatar
0 votes
0 answers
86 views

I learned to use enum class to constantize the constants involved. I also learned that using when when using enum class is very effective. I think I heard that you may not use else. Case1 may not use ...
HyeonBae Ji's user avatar
3 votes
1 answer
168 views

I have class like this: struct InsertResult{ enum class Status{ INSERTED , UPDATED_IN_PLACE , REPLACED , SKIP_INSERTED , ...
Nick's user avatar
  • 10.6k
1 vote
1 answer
103 views

I have the following code: logging.hxx #include <iostream> #include <string> #include <sstream> #include "singleton.hxx" #include "utils.hxx" class FGaugeLogger:...
TheEagle's user avatar
  • 6,005
-1 votes
1 answer
66 views

I'am new in cpp. Let's say we've got a class as follows: class Animal { public: enum class Group {mammal, bird, reptile}; private: Group group; } Now I'd like to ...
Caparso's user avatar
  • 39
0 votes
2 answers
196 views

More precisely, the feature I want is like implicitly convert an enum to its subset enum and vice versa. The code I wish it working: enum class Human { A = 1, B = 2, }; enum class Male { //...
ke_bitter's user avatar
0 votes
1 answer
60 views

I have an enum class which maps language locale to a list. How can I fix the function getReservationFrequencies inside the companion object to return the value of the map based on the locale (key)? ...
Fares Mahmoud's user avatar
5 votes
2 answers
304 views

In C++ I basically have two choices in policy based design patterns: I can use individual types (based on which an overload is selected) or specify an enum that contains all policies and I would ...
glades's user avatar
  • 5,374
1 vote
2 answers
140 views

Consider a alias template declaration, depending on a single template parameter that can have a finite number of values, like a class enum. I would like to a employ using to define a type alias for ...
francesco's user avatar
  • 7,617
1 vote
1 answer
152 views

I'm reviewing a lot of code where I need to ensure there are no static_cast (or any cast) calls on variables that could be out of range of the enum class that is being cast to. Ideally I'd be able to ...
GLJeff's user avatar
  • 147
0 votes
1 answer
128 views

I'm attempting to limit the use of this function to enum classes that have unsigned underlying types (and have AddSubtract as an enumeration) but I cannot for the life of me figure out the correct ...
GLJeff's user avatar
  • 147
3 votes
2 answers
524 views

I've been using overloaded operators as demonstrated in the second answer from here: How to use C++11 enum class for flags ... example: #define ENUMFLAGOPS(EnumName)\ [[nodiscard]] __forceinline ...
GLJeff's user avatar
  • 147
0 votes
1 answer
51 views

I'm trying to create a generic function toStr() for several enum classes but I'm having some issues. I have these enum classes and maps to convert the value of the enums to string. ''' enum class ...
Ojotuno's user avatar
  • 25
0 votes
0 answers
28 views

I observed some behavior relating to enum structs and compound operators that I don't understand (yet). When using an enum struct as a flag, I'd like to write stuff like flag &= enum_name::What. ...
rochus's user avatar
  • 1
1 vote
1 answer
595 views

I wrote a basic program to show the issue I'm dealing with. #include <iostream> using namespace std; class SomeClass { private: public: enum class SomeEnum : int {a, b, c}; ...
zalanshah64's user avatar
2 votes
3 answers
1k views

I am writing a c wrapper around a c++ library. In the c++ there are enum classes used as types for function arguments. How do I use theme correctly in the c header. One ugly way would be to use int's ...
ludw's user avatar
  • 123
0 votes
2 answers
924 views

Is there a way to initialize a container (e.g. std::unordered_set<char>) with the enumerators of an enum class? I have this class: #include <iostream> #include <unordered_set> class ...
digito_evo's user avatar
  • 3,735
5 votes
3 answers
1k views

I have an enum type in my code, like this: enum class GameConsts: size_t { NUM_GHOSTS = 4 }; I find myself repeating the required static_cast to get the enum value: Ghost ghosts[static_cast<size_t&...
Amir Kirsh's user avatar
  • 14.4k
14 votes
3 answers
16k views

I am finding that all of my standard techniques for iterating over regular enums unfortunately do NOT work on enum classes since enum classes do not implicitly convert to integers. NOT a duplicate of ...
Gabriel Staples's user avatar
0 votes
1 answer
22 views

Old code: typedef enum tagUndoAction { UNDO_CHANGE_CELL = 0, UNDO_CHANGE_SELECTION_START, UNDO_CHANGE_SELECTION_SUB } UNDO_ACTION_E; New code:...
Andrew Truckle's user avatar
0 votes
1 answer
130 views

I’m having a solution with switch cases but there are many cases so clang-tidy is giving warning for that function. My motive is to decrease the size of function. Is there any way that we can do to ...
Sasi Kamalesh Vadlani's user avatar
2 votes
4 answers
719 views

I've been working with C++ on a Time class in Qt and I need to write an enum class that contains the formats that I use in showTime(). Because of the nature of the QString formats I've been getting ...
Gio Formichella's user avatar
0 votes
0 answers
149 views

Consider an enum class enum class FOO { A,B,C }; struct something { FOO abc = FOO::A; //Compiler Doesnt like this } int main(){ something _something; return 0; } So the compiler doesnt like ...
inpinseptipin's user avatar
3 votes
1 answer
871 views

Here is a small code in which the conflict occurs. is there any way to get around this correctly? #define DEBUG 0 enum class TypeEnum : int { DEBUG = 0, INFO = 1 };
Олег Привалов's user avatar
2 votes
2 answers
1k views

I am looking for a safe and maintainable way to convert an int value to enum class. I know i can convert inegral values to enum class by simply using static_cast, but i want to make sure the value to ...
Detonar's user avatar
  • 1,429
7 votes
3 answers
1k views

I searched a bit here on SO and was surprise that I didn't find any similar question. Happy for any hints in case this has already been answered. I have a codebase with a lot of enum classes defined. ...
PluginPenguin's user avatar
0 votes
1 answer
675 views

I already found this really good explanation Initialising enum via constructors but it didn't fit my needs. So I declare an enum inside a class and want to initialize it inside the class constructor ...
sisso's user avatar
  • 3
0 votes
0 answers
164 views

To convert a strongly-typed enum to int we can use: enum class MyEnum { a, b }; int x = static_cast<int>(MyEnum::a); what if i use the following line, which is shorter: int x = int(MyEnum::a); ...
qwa's user avatar
  • 143
0 votes
2 answers
128 views

How do I index into an enum via "item index" instead of the "value indexing": "Value indexing" (not useful to me with what I am doing): eSerialBauds eBaud = static_cast&...
jdl's user avatar
  • 6,353
0 votes
2 answers
1k views

I have a function to change the state of an LED that takes in an enum argument with three possible values: enum class Command { Off, On, Toggle }; void led(Command); I'd like to be able to use the ...
Cameron Tacklind's user avatar
1 vote
1 answer
1k views

I have an enum class I use for bit masking, like so (in Unreal Engine, therefore the uint8 type) enum class Level : uint8 { None = 0x0, Debug = 0x1, Info = 0x2, Warning = 0x4, ... }...
Tare's user avatar
  • 635
0 votes
2 answers
2k views

Getting error while trying to print the enum class object. I am getting the error while trying to print this. where am I doing mistake? #include <iostream> using namespace std; int main() { ...
Suneeldatta Kolipakula's user avatar
2 votes
1 answer
855 views

I've gotten in the habit of using the new enum classes (or strong enums) in C++. Now, I need to deprecate a member. However, the standard enum deprecation syntax, as described in the following ...
Zak's user avatar
  • 12.7k
3 votes
2 answers
7k views

What is the difference between the Enum and Enum Class and how to converting Enum value to the integer in "Enum" and "Enum Class"?
Mohammad reza Kashi's user avatar
2 votes
1 answer
914 views

I have the following code in C++11 (drastically simplified to leave out the inessentials): #include <cstdint> #include <type_traits> enum class State : std::uint8_t { Shutdown, ...
mariia_kornieva's user avatar
0 votes
0 answers
188 views

Say I have a enum class foo : std::uint32_t { a = 4711, b = 815, ... }; with n enumeration constants. Assume that there actual numerical value is important. I need to pass precisely one ...
0xbadf00d's user avatar
  • 18.4k
8 votes
2 answers
5k views

I like to use enum classes, but I use them as flags sometimes and I have to constantly cast to int if I want to use a bitwise operator. Is there a way to do this without casting? I don't think you can ...
Zebrafish's user avatar
  • 16.3k
0 votes
1 answer
74 views

I'm coding in a C++ project that hasn't advanced beyond C++11 yet. Let's say I have an enum class as follows: enum class Weekdays { kSunday = 0, kMonday, ... kSaturday, }; I want to ...
Dragon s Den's user avatar
0 votes
0 answers
98 views

I have code that looks like this: enum class MyTypes { TYPE_1 = 1, TYPE_2 = 2, TYPE_3 = 3 }; static const std::regex reg1("some unique expression"); static const std::regex reg2(&...
Francis Cugler's user avatar
4 votes
3 answers
1k views

I have a piece of code that returns the value of some bits of a given number (I counted enum classes as a number too, using a static_cast). template<typename Type> bool get_bits(Type input, ...
s4eed's user avatar
  • 8,041
4 votes
1 answer
9k views

I'm probably missing something but I'm working with a code base that uses a lot of typedef enum foo { .... } foo; Is this just the same as an enum class but not strongly typed?
Joshua Williams's user avatar
3 votes
4 answers
11k views

I wanted to change an old-style enum to enum class : int because of its own scope. But the compiler complains about using the values in integer arithmetics. But why - since the enum is explicitly ...
vlad_tepesch's user avatar
  • 7,027
2 votes
1 answer
644 views

compiler : clang++ c++ standard : c++20 I tried to run the code, and the results met my expectations very well. #include <iostream> using namespace std; int main() { enum class Num : ...
nullptr's user avatar
  • 370
8 votes
1 answer
809 views

I have an event handler class that uses a template argument to set the event type. I want to enforce these event types to be enum classes of one byte size. Static assertion against the size is not an ...
Smartskaft2's user avatar
1 vote
1 answer
816 views

Is this legal C++ (>=14), resulting in a char being read and saved into aCode? enum class ECode : char { Code1 = 'a' }; std::istream& operator>>(std::istream& aIn, ECode& aCode) { ...
Felix Dombek's user avatar
  • 14.6k