Quote:Original post by SamLowry
Why wouldn't you want switch to work with more types? C#'s switch works on strings, it surely comes in handy sometimes. O'Caml/SML/Haskell use switch-like statements for pattern matching. Lisp has cond, the most general switch possible, which works with predicates (but then again can't be optimised by the compiler). And why shouldn't it also work on floating point values? Just make it smart enough so that it knows it has to work with epsilons for comparisons.
Of course, it depends on where to draw the line between what is a switch and what isn't.
I consider switch to be stylistically deprecated, with the exception of performance hacks.
Now, it's awfully useful for the hacks (and I do use it for that), but: In general, the type of behavior that switch is mean to handle is "I'm running some general purpose code, and now I'm going to specialize my action based on some sub-type." That type of thing is usually more elegantly handled with polymorphism.
All that said, if C++ did support a switch on a float, it would be a huge mistake for it to work with epsilons. C++ doesn't intrinsically support an "almost equal" for floating point types, and it wouldn't make sense to start embedding that in any extensions.