[Development] API style guide: scoped enum or not?
André Somers
andre at familiesomers.nl
Thu May 4 19:35:49 CEST 2023
On 03/05/2023 21:42, Marc Mutz via Development wrote:
> 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.
Other fallout would be that currently A, B, and C will most often
include E in their name. That makes for the code becoming
E::EA, E::EB, E::EC or E::AE, E::BE, E::CE. I don't like that. Do you
think there also is tooling to go to a renamed version w/o the enum
name? Or would it be feasible to add such tooling?
Cheers,
André
> Thanks,
> Marc
>
More information about the Development
mailing list