switch()
Ary Borenszweig
ary at esperanto.org.ar
Wed Feb 19 06:14:01 PST 2014
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
}
More information about the Digitalmars-d
mailing list