switch with regex

Unknown W. Brackets unknown at simplemachines.org
Sat Feb 25 16:43:40 PST 2006


Personally, I'd imagine that to be very strange.  You can't use any 
other operator like that in a switch, can you?

However, allowing for other comparisons might be very useful, e.g.:

switch (x, opCmp)
{
...
}

Or:

switch (x, std.regexp.test)
{
...
}

Unfortunately, this isn't very consistent with the rest of the language 
either, since it does not take callbacks like that anywhere else.

-[Unknown]


> Thoughts please:
> 
> pros?
> 
> cons?
> 
> why it won't work.
> 
> -------------
> switch(str)
> {
> case "[Tt]his"~~:
> writef("Doing this");
> break;
> 
> case "[Tt]hat"~~:
> writef("Doing this");
> break;
> 
> case ".*somthing.*"~~:
> writef("Doing somthing");
> break;
> 
> default:
> writef("Doing nothing");
> break;
> }
> 
> 



More information about the Digitalmars-d mailing list