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

Stephen Kelly steveire at gmail.com
Fri Jun 16 00:23:47 CEST 2023


On 15/06/2023 22:20, Allan Sandfeld Jensen wrote:
> On Mittwoch, 14. Juni 2023 22:53:13 CEST Thiago Macieira wrote:
>> On Wednesday, 14 June 2023 12:49:22 PDT Allan Sandfeld Jensen wrote:
>>> As discussed earlier. Better naming in many cases until we can depend on
>>> C++20 in API.
>>
>> There's nothing in C++20 that would allow us to design APIs differently.
>>
>> You may be thinking of C++23 "using enum" feature, which is barely supported
>> anywhere and doesn't help us in any way I can see. It might allow us in the
>> future to change our existing unscoped enums to scoped, but until then
>> there's little we ca do.
>>
> Correct. I was referring to "using enum", which had been referred to as C++20
> by Marc. It could allow "type safe" enums without scope.

It is c++20:

  https://godbolt.org/z/3nMh43jxz

And, you can introduce it in a way which is source-compatible until the 
user upgrades their compiler to a compiler version which implements 
`using enum`:

  https://godbolt.org/z/4EWjWhvfa

This looks valuable to me and in line with how Qt usually introduces 
usage of newer C++ features. I don't recall whether Qt finds a break 
like that acceptable when the user updates the compiler.

Thanks,

Stephen




More information about the Development mailing list