[Development] API style guide: scoped enum or not?
Hasselmann Mathias
mathias at taschenorakel.de
Thu Jun 15 21:22:35 CEST 2023
Am 04.05.2023 um 15:51 schrieb Sune Vuorela:
> In few cases the implicit conversion to underlying_type is kind of
> important.
> Especially in the cases where the api has int and is mostly used with
> enums or is somehow user extendable.
>
> Qt::ItemDataRole is one of them that comes to mind.
>
> switch(role) {
> case Qt::UserRole+1:
> ....
I'd argue you are using role wrong. For my models I always define a
DataRole enum. With that enum all my role related switch statements
looks like this:
switch (static_cast<DataRole>(role)) {
}
Big advantage of explicitly casting the int to my DataRole: The compiler
tells me if I forget to handle any of my supported roles.
Ciao
Mathias
More information about the Development
mailing list