request switch statement with common block

MattCodr mattcoder at hotmail.com
Mon Aug 5 04:16:05 PDT 2013


On Monday, 5 August 2013 at 04:07:55 UTC, Andre Artus wrote:
>
>>> Andre Artus:
>>> int number;
>>> string message;
>>> switch (number)
>>> {
>>> 	default: // valid: ends with 'throw'
>>> 		throw new Exception("unknown number");
>>> 	case 3:
>>> 		message ~= "three "; break;
>>> 	case 4:
>>> 		message ~= "four "; continue;
>>> 	case 5:
>>> 		message ~= "five "; goto case;
>>> 	case 6:
>>> 		message ~= "six "; break;
>>> 	case 1:
>>> 	case 2:
>>> 		message = "one or two";
>>> }
>>>
>>> With the inclusion of 'default' the condition covers the 
>>> whole range of 'int'. The programmer may only want the pre  
>>> and post code to be executed for every other case (1..6).
>
>> MattCoder:
>> Like I said, it would be nice if we could extend some D 
>> features without change the compiler source, maybe like macros 
>> in LISP.
>
> It may not always be the case, but in my experience this often 
> leads to write-only code.
> I'm pretty new to D, so I'm not quite up to speed with the 
> metaprogramming abilities, but I'm under the impression that 
> this is what mixin's are for.

Well I'm not experienced too, but mixin's for what I know just 
works in compiler time right?

But anyway it would be possible to write my own switch version 
with mixin? I really would like to see this.

Matheus.


More information about the Digitalmars-d mailing list