C++11 Mapping for Enumerations

A Slice enumeration maps to the corresponding enum class in C++.

For example:

Slice
enum Fruit { Apple, Pear, Orange }

The generated C++ enumeration is:

C++
enum class Fruit : unsigned char { Apple, Pear, Orange };

The underlying type is unsigned char when the enumeration's largest enumerator value is not greater than 254, otherwise it's the default, int.

You can alternatively generate an old-style unscoped enum with the cpp:unscoped metadata directive.

Suppose we modify the Slice definition to include a custom enumerator value:

Slice
enum Fruit { Apple, Pear = 3, Orange }

The generated C++ definition now includes an explicit initializer for every enumerator:

C++
enum class Fruit : unsigned char { Apple = 0, Pear = 3, Orange = 4 };

If you use custom enumerator values and 0 does not correspond to any enumerator, you must be particularly careful with structs, classes or exceptions that have such as enumeration as a data member. The default constructor of such a struct, class or exception will zero-initialize this data member, and you will get a marshal error if you attempt to send this invalid enumerator through Ice.

See Also