How to search for an enum by values and why enum items aren't unique
Ali Çehreli via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Jul 20 11:20:54 PDT 2016
On 07/19/2016 09:03 PM, stunaep wrote:
> And why on earth are different enum items with the same values
> equal to each other?
I've seen code where it made sense. Searching for an example reveals:
enum Scope
{
Transient,
Singleton,
Default=Transient
}
> Seems to me like there's no reason to even use enums in D.
I don't know how they are used in Java but they are very common in
C-style code like your if-else if chain is. (Equally useful with the
switch statement). There are other ways of achieving the same thing; OOP
is just one.
> What's the point when just making a constant would do the same
> exact thing?
enum groups a set of values under a type. For example, you can write a
function that accepts enum Color and it expects just the values that it
contains. I think it's useful.
Ali
More information about the Digitalmars-d-learn
mailing list