Implicit enum conversions are a stupid PITA
Lutger
lutger.blijdestijn at gmail.com
Mon Mar 29 12:16:02 PDT 2010
Lutger wrote:
...
>
> unittest
> {
> alias Flags!q{ do_nothing, walk_dog, cook_breakfast, deliver_newspaper,
> visit_miss_kerbopple, morning_task = walk_dog | cook_breakfast,
> wash_covers } Todo;
>
> Todo list1 = Todo.do_nothing;
> assert( list1 == 1 );
> list1 |= Todo.wash_covers | Todo.walk_dog;
> assert(list1 == Todo.do_nothing | Todo.wash_covers | Todo.walk_dog);
> assert(Todo.do_nothing in list1);
>
> Todo list2 = Todo.cook_breakfast | Todo.wash_covers;
> assert( list1 & list2 == Todo.do_nothing | Todo.cook_breakfast);
> list1 = list2;
> assert(list1 == Todo.do_nothing | Todo.wash_covers | Todo.walk_dog);
>
> assert( Todo.morning_task == Todo.walk_dog | Todo.cook_breakfast );
>
> auto list3 = Todo.deliver_newspaper;
> assert(Todo.deliver_newspaper in list3, "can't infer type properly");
> /*
> bug */
> }
^
oops, this one is totally messed up and needs to go to precedence school.
This should be better:
unittest
{
alias Flags!q{ do_nothing, walk_dog, cook_breakfast, deliver_newspaper,
visit_miss_kerbopple, morning_task = walk_dog |
cook_breakfast, wash_covers } Todo;
Todo list1 = Todo.do_nothing;
assert( list1 == 1 );
list1 |= Todo.wash_covers | Todo.walk_dog;
assert(list1 == (Todo.do_nothing | Todo.wash_covers | Todo.walk_dog) );
assert(Todo.do_nothing in list1);
Todo list2 = Todo.cook_breakfast | Todo.wash_covers;
assert( (list1 & list2) == Todo.wash_covers );
list1 = list2;
assert(list1 == (Todo.cook_breakfast | Todo.wash_covers) );
assert( Todo.morning_task == (Todo.walk_dog | Todo.cook_breakfast) );
auto list3 = Todo.deliver_newspaper;
/* bug */
assert(Todo.deliver_newspaper in list3, "can't infer type properly");
}
More information about the Digitalmars-d
mailing list