Religeous wars about the proper way to do things are often dumb because they are often so theoretical that they lose sight of the fact that a problem has to be solved. Religeous convictions have a place though because they can be guidance when it is difficult to figure out all of the implications of a choice. I can't really say whether or not your code is in a state of grace, but I can lay out some of the issues by which to decide that. That is, you pass in an object of unknown type and you want to do something appropriate with it that depends on the full type. The alternative run-time polymophism way to do this is to use virtual functions.
Virtual function are faster.
The amount of time it takes to resolve the type does not scale up with the number of possible classes. Virtual functions are extensible. Given a library that uses virtual functions you can always derive a new class that defines a new foo and it works. If the function above was compiled into a library you could not add a new kind of matrix to it. That generally means you can add functionality to your library, but I can't.