Is it possible to use std :: byte as the base type for the enum class?

Since std::byteby definition it is not an integral type, the following fragment is poorly formed:

enum class foo : std::byte
{
    bar = 1,
    baz = 2
};

Is there a way in C ++ 17 to do something equivalent to this?

Edit: I am not trying to solve any specific problem. Obviously, that enum class whatever : unsigned charwill do it. However, I expected it to std::bytebe a little more flexible and would like to know if this is possible at all.

+4
source share
2 answers

std::byte defined by the standard , should be enum class. Therefore, it has a base type ( unsigned char). Thus, you can create an enumeration with the same base type:

enum class foo : std::underlying_type_t<std::byte>
{...};
+8
source

unsigned char uint8_t.

+3

Source: https://habr.com/ru/post/1690648/


All Articles