Skip to main content
Filter by
Sorted by
Tagged with
1 vote
1 answer
1k views

I wasn't able to show documentation for values of enum classes without setting EXTRACT_ALL. The comments for preserve, truncate and append aren't there. The enum itself is documented. If I enable ...
Martin Fehrs's user avatar
  • 1,175
1 vote
2 answers
594 views

I have a struct which takes enum class value on the template parameter. template <typename EnumValue> struct Type { public: static constexpr int VALUE = static_cast<int>(EnumValue); }; ...
Mojtaba Shahbazi's user avatar
1 vote
5 answers
4k views

Enum classes are supposed to be strong enums in the sense that they don't implicitly convert to and from int. For instance: enum class EC { a, b }; However, when switching over such a "strong enum": ...
bitmask's user avatar
  • 35.2k
7 votes
3 answers
610 views

I have: enum class orientation { North, East, South, West }; I want to rotate its instance left (North => West) and right (West => North). But I don't want to convert them to numbers, because ...
Lukas Salich's user avatar
  • 1,020
0 votes
1 answer
166 views

As a rule of thumb on forward declaration (from "API Design for C++", p. 214), I only include the header of a class if I: use an object of that class as a data member in my own class, or inherit from ...
gmargari's user avatar
  • 171
1 vote
2 answers
1k views

OperatingSystem.h #ifndef OPERATING_SYSTEM_H #define OPERATING_SYSTEM_H #include <iostream> enum class OperatingSystem { unknown, android, iOS, macOS, Linux, ...
Alberto Cruz Luis's user avatar
1 vote
1 answer
163 views

I'm abstracting the interrupt vector table on multiple microcontrollers. I am using template classes in the form of (InterruptVectorTable.hpp(definition, included in implementation)) template<...
John Behm's user avatar
  • 101
2 votes
2 answers
2k views

Say we have an enum type foo which we want to use to index an array arr of static size. If we want to use an enum class for this, we could try it like this: enum class foo { a, b, c, ...
0xbadf00d's user avatar
  • 18.4k
4 votes
2 answers
1k views

I'm trying to achieve the following behavior in a python "enum" (so far to no success): Given the enum class class MyEnum(enum.Enum): A=1 B=2 C=3 I want to have an "Other" member such ...
EZLearner's user avatar
  • 1,864
1 vote
0 answers
2k views

I have a constructor of an object that can throw an exception if a parameter of an enum class type is wrong. This permits me to ensure that such an object, that will use that parameter for some ...
Zack's user avatar
  • 127
5 votes
3 answers
2k views

I am generally using clang to develop code, using all reasonable warnings I can (-Wall -Wextra [-Wpedantic]). One of the nice things about this setup is that the compiler checks for the consistency of ...
alfC's user avatar
  • 16.8k
0 votes
2 answers
389 views

I'm trying to write a generic container class that I can use as a library. I want to use it to instantiate each object in a collection exactly once. So I thought to pass in both the pointer to the new ...
Paauwer's user avatar
5 votes
1 answer
7k views

In this answer it was mentioned that in the upcoming C++20 standard it is possible to use the using statement on enum class and import the enum fields into the local namespace. I was wondering if ...
the_summer's user avatar
2 votes
1 answer
125 views

I encounter the following code in C++. I am new to the language and am not familiar with the syntax. I understand the basic of macro expansion and enum class. I learn that the macro etokenize with ...
Ryan's user avatar
  • 249
5 votes
0 answers
532 views

With the following code I can check at compile time if type E is an enum: static_assert(true == std::is_enum<E>::value, "Must be an enum"); How can I check if it is an enum class? Here they ...
Pietro's user avatar
  • 13.5k
2 votes
1 answer
2k views

I'm using private enum class in nested class and want to implement operator! for my enum class. I know how to do this. But when I tried to overlord operator of enum class in nested class, compiler ...
jumho park's user avatar
0 votes
1 answer
2k views

I'm attempting to overload some operators for an Enum class. I get a compiler error saying it's unable to find the operator In Enum.h enum class SomeEnum : unsigned { Test0 = 0, Test1 = (1 &...
user avatar
0 votes
1 answer
1k views

I'm having issues using an enum class as a type specifier within an unordered_map. I've trawled the internet but had no luck with any of the solutions. Closest example I found was at the link below, ...
GreenaGiant's user avatar
0 votes
1 answer
632 views

Following advice from Qt documentation and this question's answers, I have code structured like so: emulator.h: class Emulator : public QObject { Q_OBJECT public: enum HaltCause ...
Brian A. Henning's user avatar
0 votes
1 answer
172 views

I have the two code examples below. Both of them interprete an enum or enum class as their underlying type. Which one would be smaller after compilation when using multiple different enums? Working ...
Bart's user avatar
  • 1,630
2 votes
1 answer
1k views

I want to fill a variable with random element from enum class. So I tried set enum class type to int and pass last enum from enum class to rand: enum class Enumerator: int { en1=0, en2, ...
LVlad's user avatar
  • 23
4 votes
2 answers
990 views

I've looked all over the place and I can't believe this question has not been asked before. Is the ordering of scoped enumerators defined by the standard? Say if I have the following #include <...
GamefanA's user avatar
  • 1,645
0 votes
0 answers
33 views

I like to define my enum's that belong to a certain class inside that class. That makes it clear they belong together and helps against namespace pollution: class Bar { public: enum class Foo ...
Unimportant's user avatar
  • 2,096
9 votes
2 answers
6k views

I have this situation on one Project where we have some socket-communication that mainly exchanges characters for flow-control. We cast those characters to an enum class : char in a switch. I was ...
bam's user avatar
  • 1,014
0 votes
0 answers
69 views

I'm writing an EnumSet class for a project. I would like to have an EnumSet::AllOf() method if possible, like in Java. The obvious way to go about this is to iterate over every member of the std::...
Q Science's user avatar
  • 111
3 votes
1 answer
766 views

I'm writing a simple Naive Bayes image classifier in C++. I'd like to parametrize it by two enum class types (one for the type of input pixels, one for the class of the image). The problem is that ...
Q Science's user avatar
  • 111
0 votes
2 answers
663 views

I am working on a senior project and having a question about how to best implement a lookup table for my program. There are several enum class files that contain enum classes and an operator<< ...
jleibman's user avatar
  • 167
2 votes
1 answer
606 views

I have an enum class like this (I am planning to add more options to it later): enum class ViSequencePointType { JumpToValue = 0, RampToValue = 1 }; Then I have a configuration text file which ...
DEKKER's user avatar
  • 933
2 votes
2 answers
2k views

I am trying to serialize and deserialize (using QDataStream but that is irrelevant here) an enum class variable: enum class Type : char { Trivial, Complex }; The serialization is easy: ...
Resurrection's user avatar
  • 4,126
0 votes
2 answers
104 views

I have several enums defined as follows: enum class Suit { spades = 1, hearts, diamonds, clubs, first = spades, last = clubs }; enum class Rank { six = 6, seven, eight, nine, ten, jack, ...
sergej's user avatar
  • 18.2k
0 votes
1 answer
186 views

I have an enum class in C++11: enum class eDays{ SUNDAY, MONDAY, /*...*/ }; The enum class sets the namespace for the values so it has to be used like: eDays::SUNDAY I want to set an namespace block ...
igor's user avatar
  • 742
11 votes
2 answers
384 views

Let's say that I'm crazy and decided to create the following monstrosity: #include <type_traits> #include <iostream> // Utility proxy type - convertible back to E but also permits bool ...
Lightness Races in Orbit's user avatar
0 votes
1 answer
575 views

I was reading the sample code on another post Specializations only for C++ template function with enum non-type template parameter and I'm trying to take it one step further, by using a overloaded ...
cicero866's user avatar
  • 175
0 votes
1 answer
255 views

I was hoping someone could help me out with an error I'm having using an enum class in a switch case. trying to use the traverse type to choose the path in the switch. Here is my code: enum class ...
D. Spani's user avatar
-2 votes
1 answer
3k views

I have a construction that takes a std::set as a parameter. How do I initialize the set in the constructor parameter? Here's an minimal conceptual example. Actual implementation is much larger. #...
Thomas Matthews's user avatar
14 votes
2 answers
786 views

The following code is accepted by clang 6.0.0 but rejected by gcc 8.2 enum class E { Good, Bad, }; struct S { E e : 2; int dummy; }; S f() { return {E::Good, 100}; } Live godbolt example ...
Kan Li's user avatar
  • 8,837
3 votes
2 answers
6k views

I have an object that has an enum type as a member. enum class Color { Blue=1, Green=2, Red=3}; struct A { int f; Color color; A(int x, Color c) : f(x), color(c) {} }; struct B{ ......
ssh's user avatar
  • 419
8 votes
1 answer
311 views

P0138R2 proposal begins with1 There is an incredibly useful technique for introducing a new integer type that is almost an exact copy, yet distinct type in modern C++11 programs: an enum class ...
Evg's user avatar
  • 26.6k
0 votes
2 answers
2k views

enum class Fruit { apple, orange, pear }; enum class Color { red, green, orange }; template <typename T> struct Traits; //I have to return the appropriate value(string) of color and fruit in ...
Siddharth Pandey's user avatar
2 votes
1 answer
302 views

There are a lot of feature test macros in C++ which give a simple and portable way to detect the presence of C++ standards and experimental features. However, I didn't manage to find simple macros to ...
Seleznev Anton's user avatar
1 vote
3 answers
3k views

I am trying to write the contents of a class object into a file. The object has an enum class member and I am unable to write it into a file using ofstream. I get the following error. error: no ...
Abhishek V's user avatar
-2 votes
1 answer
325 views

I had this question on a test. I know that I can do something like: enum class Color { red, green = 1, blue }; Color c = Color::blue; if( c == Color::blue ) cout << "blue\n"; But when I ...
vister's user avatar
  • 29
0 votes
1 answer
80 views

I wanted to check if the tags returned from a json object has one of the values inside an enum class. Gson gson = new Gson(); AnalysisResult result = gson.fromJson(data, AnalysisResult....
joycecruz's user avatar
3 votes
2 answers
1k views

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 ...
dosvarog's user avatar
  • 754
3 votes
3 answers
1k views

Here is what I need to do: define, inside a class, two enumerations, the second having elements defined using elements values from the first. So something like this: class MyClass { public: ...
Silverspur's user avatar
8 votes
3 answers
8k views

I have defined a tuple and its indices by creating an enum class: /** parameter { key ; value1 ; value1 ; } */ using Parameter = std::tuple<unsigned, unsigned, unsigned>; enum class ...
sukovanej's user avatar
  • 688
-1 votes
1 answer
480 views

I have code that contains the line enum struct cols: int8_t {red, blue, green}; When i compile this, i get errors: test.cpp:4:1: warning: elaborated-type-specifier for a scoped enum must not use ...
user1479670's user avatar
  • 1,355
0 votes
1 answer
897 views

Even though I'm working with Bukkit, this is a Java problem; I don't know, why Java says the constructor is undefined, since it is defined import org.bukkit.entity.EntityType; import net.minecraft....
SlamWeasel's user avatar
1 vote
2 answers
1k views

Let's say I have an alias for vector: typedef std::vector<double> PlanetData; And I want it's fields to be accessible via some keys: double x = planet_data[PlanetDataKeys::PosX]; //planet_data ...
Przemysław Czechowski's user avatar
1 vote
2 answers
2k views

When I define an enum class inside a function, it has a value from the available options. However, when I define it within a class, it has value of none of the options. So what is the initial value of ...
ar2015's user avatar
  • 6,250