fix issue 9959 - Add functional pattern matching for object references

Add the function std.algorithm.castSwitch, which chooses a delegate
based on the class of an object and run that delegate with that object.