overloading operations for enums
Rene Zwanenburg via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon May 26 10:14:45 PDT 2014
On Monday, 26 May 2014 at 16:54:02 UTC, Dominikus Dittes Scherkl
wrote:
> Hello.
>
> I want to create some finite algebra, where the elements are
> enumerated but operations on them are defined (with composition
> tables).
>
> e.g.:
>
> enum color = { white, yellow, red, blue, orange, violet, green,
> black };
>
> color a = blue;
> a += yellow;
> assert(a == green);
>
> is this possible in D?
>
> Because, if I define a struct, I can define operation
> overloads, but then I have no enumeration of possible values.
> But if I enumerate, I cannot
> overload operations.
> What have I missed?
You can make an enumeration of structs:
struct S
{
int i;
}
enum E
{
Something = S(1),
SomethingElse = S(2)
}
More information about the Digitalmars-d-learn
mailing list