On 11/13/2018 3:29 PM, Rubn wrote:
enum : int { a = 127 }
To reiterate, this does not create an anonymous enum type. 'a' is typed as
'int'. Technically,
`a` is a manifest constant of type `int` with a value of `127`.
> enum A : int { a = 127 }
`a` is a manifest constant of type `A` with a value of `127`.
Remember that `A` is not an `int`. It is implicitly convertible to an integer
type that its value will fit in (Value Range Propagation). Other languages do
not have VRP, so expectations from how those languages behave do not apply to D.
VRP is a nice feature, it is why:
enum s = 100; // typed as int
enum t = 300; // also typed as int
ubyte u = s + 50; // works, no cast required,
// although the type is implicitly converted
ubyte v = t + 50; // fails
In your articles, it is crucial to understand the difference between a manifest
constant of type `int` and one of type `A`.