Re: type switch

2015-05-05 Thread Dennis Ritchie via Digitalmars-d
On Tuesday, 5 May 2015 at 18:37:52 UTC, Justin Whear wrote: How's this? http://dpaste.dzfl.pl/d6643ec8ccd3 Yes, something like that. In my opinion, it's really easier than static if in some cases.

Re: type switch

2015-05-05 Thread Dennis Ritchie via Digitalmars-d
On Tuesday, 5 May 2015 at 18:12:42 UTC, Ali Çehreli wrote: Personally, I haven't felt the need for this becuase usually there is something different only for one or two specific types. I don't see that the syntax becomes shorter to warrant a language addition either. (However, the risk of writ

Re: type switch

2015-05-05 Thread Justin Whear via Digitalmars-d
How's this? http://dpaste.dzfl.pl/d6643ec8ccd3

Re: type switch

2015-05-05 Thread Ali Çehreli via Digitalmars-d
se static if (is(T == real)) { > // ... > } else static if (is(T == char)) { > // ... > } else static if (is(T == string)) { > // ... > } else static if (is(T == int[])) { > // ... > } else { > // ... > } > > Why not put in Phobos shorter des

Re: type switch

2015-05-04 Thread Dennis Ritchie via Digitalmars-d
On Monday, 4 May 2015 at 22:48:37 UTC, Dennis Ritchie wrote: Why not put in Phobos shorter design type switch: *More precisely, not in Phobos and DMD.

type switch

2015-05-04 Thread Dennis Ritchie via Digitalmars-d
(is(T == char)) { // ... } else static if (is(T == string)) { // ... } else static if (is(T == int[])) { // ... } else { // ... } Why not put in Phobos shorter design type switch: // - type switch (T) { case short, int, long: // do anything case

Re: type switch

2009-09-01 Thread Jarrett Billingsley
r a string, an enum for a symbol or keyword, etc. So the type of the value > field is "object", and you use the token type to tell you how to cast the > value field when you use it. > > The Lava solution to this problem is to allow an explicit type switch: > > switch (valu

type switch

2009-09-01 Thread Paul D. Anderson
how to cast the value field when you use it. The Lava solution to this problem is to allow an explicit type switch: switch (value.type) { case int: // value is an int value += 3; break; case string: // value is a string string sub = substring(value, 1, 5); break; ca