I love Haskell style pattern matching.
Then write your program in Haskell.
What you're trying to do is a switch over a type. That's a common thing people do if they want to avoid virtual functions. Now, the latter are a cornerstone of what OO in C++ is all about. If you want to avoid them, why do you program in C++?
As for why this is frowned upon: Imagine you have a lot of code like this
if(ptr.isType<Foo>()) ...
if(ptr.isType<Bar>()) ...
smeared all over your code and then someone comes and adds Baz
to the possible types that ptr
might represent. Now you're hunting through a big code base, trying to find all those places where you switched over a type, and trying to find out which ones you need to add Baz
to.
And, as Murphy has it, just when your done, there comes along Foz
to be added as a type, too. (Or, thinking again, if Murphy has his way it creeps in before you had a chance too complete adding Baz
.)