On 2011-04-03 11:03, Aleksandar Ružičić wrote:
> As far as I understand, manifest constants and enums only share the
> same keyword (enum) and are completely different things.
> Enumerations (like enum A { a,b, c}) define new type, while manifest
> constants (like enum N = 42;) are just constant values with type
> inferred from value (unless specified after enum keyword).They're the same and they're not. A named enum creates a new type of sorts and namespaces the values in it, whereas a manifest constant does not create a new type and its values (be it one or many) go directly in the namespace that it's declared in. But even a named enum doesn't exactly create a new type. It's really its base type everywhere it's used, but extra restrictions are put on it to help ensure that only valid values are used with it. For example, with std.datetime.Month, you either have to use Month.jan, Month.feb, etc. or cast an integral value to a Month - e.g. cast(Month)12. However, it's still only a ubyte when it's compiled in, because Month is an enum of the type ubyte. So, manifest constants and named enums are not quite the same thing, but they're not drastically differente either. Their values act essentially the same way. They're just referenced differently, and you can refer to the name of a named enum, using it as a type, whereas there is no name for a manifest constant. Their values are pretty much identical when they're used though. - Jonathan M Davis
