3

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 part of the spec requires me to be able to write the classifier to a file, so I need to be able to get the integer values of all elements in the enum classes in question. This, of course, requires me to get all the values from the enum classes in question.

In Java, I can write

EnumSet.allOf(PixelTypeEnum.class)

to get a set containing every element of the enum class. Is there a similar idiom in C++?

Q Science
  • 111
  • 7

1 Answers1

1

No, there isn't. That's because C++ does not have reflection.

There are some approaches you can take to mimicking EnumSet (e.g. this FlagSet implementation which I've been using, and to which I did add a trivial setAll function), but nothing built-in.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055