[Development] API style guide: scoped enum or not?

Marc Mutz marc.mutz at qt.io
Wed May 3 21:42:50 CEST 2023

On 03.05.23 20:06, A. Pönitz wrote:
> My main problem with enum classes _in Qt_ is that it is inconsistent
> with what has been there traditionally. It is simply no fun to guess
> what "style" some enum is (and sure, Peppe has a point when hinting that
> the naming scheme wasn't applied uniformly in the pre-past either...)

There is a pretty straight-forward migration path (and I'm sure that 
clang-tidy has an automatic transformation already):

For amy unscoped

     enum E { A, B, C, };

you can, since C++11, write

     E::A, E::B, E::C

This rewrite is an automatable task, and, once done, we can make E 
scoped, and just have to deal with (desired) fallout of the missing 
implicit conversion to underlying_type.

So if your problem is consistency, then just scope the unscoped 
enumerators in your code as if they were scoped.


Marc Mutz <marc.mutz at qt.io>
Principal Software Engineer

The Qt Company
Erich-Thilo-Str. 10 12489
Berlin, Germany

Geschäftsführer: Mika Pälsi, Juha Varelius, Jouni Lintunen
Sitz der Gesellschaft: Berlin,
Registergericht: Amtsgericht Charlottenburg,
HRB 144331 B

More information about the Development mailing list