Path: utzoo!attcan!uunet!husc6!uwvax!tank!shamash!nis!sialis!orbit!pnet51!shawn From: shawn@pnet51.cts.com (Shawn Stanley) Newsgroups: comp.lang.c++ Subject: Re: Improved switch statement Message-ID: <437@orbit.UUCP> Date: 27 Dec 88 18:05:04 GMT Sender: root@orbit.UUCP Organization: People-Net [pnet51], Minneapolis, MN. Lines: 30 nevin1@ihlpb.ATT.COM (Liber) writes: >In article <574@redsox.UUCP> campbell@redsox.UUCP (Larry Campbell) writes: > >|I think it would be eminently sensible for the switch statement to operate >|on any type that has an == operator defined; of course the case labels would >|have to be the correct type (or coerced thereto). > >You have to be far more restrictive than that. Not only must >operator== be defined, but it must be defined to return a scalar (since >the controlling expression of an if statement must have scalar type). >Note: you can't easily use implicit type conversion, since there is no >way of telling which of the scalar types (pointer, float, int, etc.) >the return value should meaningfully be converted to. I would think that either the switch() operand's type or the case operand's type would be used. Most probably case, since that would allow greater flexibility. This would imply: switch(x) { case y: ... } In this instance, the above would be the same as (y == x), which would use the type of (y) and convert (x) to that type for the compare. UUCP: {rosevax, crash}!orbit!pnet51!shawn INET: shawn@pnet51.cts.com