D - Switch statement operator overload
- J Anderson (47/47) Dec 16 2003 This is probably a silly idea (I can't think of a practical
- Ilya Minkov (4/6) Dec 16 2003 Object has a predefined method to covert itself to hash. I think this
- J Anderson (2/8) Dec 16 2003 Does it. That's a good idea!
- J Anderson (3/17) Dec 16 2003 Actually I was just looking through phobos. Switch.d seems to do
- J Anderson (4/24) Dec 16 2003 Does it. That's a good idea!
-
Matthew Wilson
(6/32)
Dec 17 2003
A man after my own heart. Obsessed with the minutiae.
This is probably a silly idea (I can't think of a practical application), but I'll post it anyway for comment. What about the ability to override the switch statement for an object, kinda like opApply for foreach. class Obj { int opSwitch(Obj cmpVal, Obj [] cases) { ... } } ... Obj A = new Obj; Obj B = new Obj; Obj C = new Obj; switch (A) { case B: //1 break; case C: //2 break; default: //3 } would be like typing: switch (opSwitch(A, {A, B})) { case 0: //1 break; case 1: //2 break; case -1: //default //3 break; } Alternative, more powerful syntax for opSwitch could be: void opSwitch(Obj cmpVal, Obj [] cases, Obj delegate() [] solution) { } Where solution is a delegate that points to the cases statement that would run when it is called. It might be useful, if there user wishes to define how a particular case determines an answer (ie what search algorithm), or for fuzzy cases (ie going for the most-likely best choice). It's probably a dumb idea, but I'm just putting it up for discussion anyways.
Dec 16 2003
J Anderson wrote:This is probably a silly idea (I can't think of a practical application), but I'll post it anyway for comment.Object has a predefined method to covert itself to hash. I think this should work with switch then. -eye
Dec 16 2003
Ilya Minkov wrote:J Anderson wrote:Does it. That's a good idea!This is probably a silly idea (I can't think of a practical application), but I'll post it anyway for comment.Object has a predefined method to covert itself to hash. I think this should work with switch then. -eye
Dec 16 2003
J Anderson wrote:Ilya Minkov wrote:Actually I was just looking through phobos. Switch.d seems to do something like I originally suggested.J Anderson wrote:Does it. That's a good idea!This is probably a silly idea (I can't think of a practical application), but I'll post it anyway for comment.Object has a predefined method to covert itself to hash. I think this should work with switch then. -eye
Dec 16 2003
J Anderson wrote:J Anderson wrote:Does it. That's a good idea! Should have been (just realised that I could be misinterpreted): Does it? That's a good idea!Ilya Minkov wrote:Actually I was just looking through phobos. Switch.d seems to do something like I originally suggested.J Anderson wrote:Does it. That's a good idea!This is probably a silly idea (I can't think of a practical application), but I'll post it anyway for comment.Object has a predefined method to covert itself to hash. I think this should work with switch then. -eye
Dec 16 2003
A man after my own heart. Obsessed with the minutiae. <G> Matthew P.S. btw, I think your idea is appealing, if only because it shows how other "built-in" operations might be given some under-the-covers tailorability "J Anderson" <REMOVEanderson badmama.com.au> wrote in message news:brnjq9$1mja$1 digitaldaemon.com...J Anderson wrote:J Anderson wrote:Does it. That's a good idea! Should have been (just realised that I could be misinterpreted): Does it? That's a good idea!Ilya Minkov wrote:Actually I was just looking through phobos. Switch.d seems to do something like I originally suggested.J Anderson wrote:Does it. That's a good idea!This is probably a silly idea (I can't think of a practical application), but I'll post it anyway for comment.Object has a predefined method to covert itself to hash. I think this should work with switch then. -eye
Dec 17 2003