Could you please have these 3 classes be subclasses with the same parent? main still needs to be assigned for testing using the right subclass, but the test itself will be declared a common superclass.
The disadvantage here is that there may be a (possibly slight) performance hit, since the compiler would not know when creating the code for test.loop which version will be used, and therefore it will have to decide at runtime.
An alternative that would get around this would be to write a generic code in the form of a macro, which would thus only be written once, but expanded into 3 separate copies, each of which the compiler could optimize based on the variant of the test to be used. It can make debugging a bitch, but if your focus is on performance and reduces source redundancy (and not so much for the object), this can be a good compromise.
source share