How do I create a class type that can "wrap" enums and have the same conversions behavior? See https://compiler-explorer.com/z/Ys3M1M3sn for the problem I believe is impossible to solve: A `std::byte` (enum class) can be static_cast-ed but not function-style casted. A class type opts in/out for both at the same time. There's no way to distinguish the two, correct?
(FWIW, I don't understand why enum classes have this extra restriction.)
@mkretz std::byte can also be function-style casted: https://compiler-explorer.com/z/zKs88MKP1
What it can't do is initialized, because (TIL) direct initialization of non-class types only does implicit conversions: https://eel.is/c++draft/dcl.init#general-16.9.sentence-2
That is weird.
Edited 4d ago
@foonathan Right @DanielaKEngert and you just made it weirder. So function-style cast does work. Very much feels like a wart and not a feature.
@mkretz @DanielaKEngert Yeah, I think:
T t(x);
and
auto t = T(x);
should be equivalent. Right now, they are equivalent for all types except for scoped enums (AFAICT).
Maybe the relevant sentence should be changed to talk about doing a functional cast, not an implicit conversion.