switch()
QAston
qaston at gmail.com
Wed Feb 19 06:17:58 PST 2014
On Wednesday, 19 February 2014 at 14:14:01 UTC, Ary Borenszweig
wrote:
> On 2/19/14, 6:42 AM, Daniel Murphy wrote:
>>
>> "Steven Schveighoffer" wrote in message
>> news:op.xbhnw5rbeav7ka at stevens-macbook-pro.local...
>>
>>> It may not be mindless. Most people who want to handle the
>>> default
>>> case do it. It's usually not so much "I didn't think of
>>> handling other
>>> values," it's more "I never expect other values to come in,
>>> go away
>>> annoying compiler error."
>>
>> So why not put an assert(0) in instead of a break? Tell the
>> compiler
>> that you're assuming there are no other possible values. This
>> is
>> obviously the right thing to do here, and even if you ignore
>> it the
>> compiler _is_ trying to help you.
>
> Sometimes you don't care about other values, which is different
> than not expecting other values. For example:
>
> auto a = ...;
> switch(a) {
> case 1: a += 1;
> case 2: a += 2;
> // In other cases, leave "a" as is
> }
Just put default: break instead of that comment, it's shorter
that way:P
More information about the Digitalmars-d
mailing list