Implicit enum conversions are a stupid PITA

bearophile bearophileHUGS at lycos.com
Sun Mar 28 03:46:14 PDT 2010


Lutger:
>I can brush it up and post the code later if you want, but it's not so pretty.<

This syntax is not pretty, but I think it can be acceptable:

alias Flags!q{
    do_nothing,
    walk_dog,
    cook_breakfast,
    deliver_newspaper,
    visit_miss_kerbopple,
    wash_covers
} Todo;

With optional type too:

alias Flags!q{ int :
    do_nothing,
    walk_dog,
    cook_breakfast,
    deliver_newspaper,
    visit_miss_kerbopple,
    wash_covers
} Todo;


Now it's a matter of writing a good amount of CTFE to implement the little parser, to create the methods and attributes, to perform the necessary sanity tests in all inputs, to write documentation, tests, etc :o)
I don't need flags often in my code so don't implement it for me. If you have some free time you can write it for other people here. Once the code is good probably Andrei will accept to put it in Phobos2.

Bye,
bearophile



More information about the Digitalmars-d mailing list