Daily bit(e) of C++ #117, The dependency injection design pattern.
simple, though powerful, useful and important
I've been looking for a way to do this at compile time using templates but haven't found a solution. Is such a thing possible?
With templates you don't get a common type.
Typically that means that at some point you will need some form of type erasure to stop the propagation of the templates.
If your goal is to get rid of the virtual methods, it is achievable: https://www.linkedin.com/posts/simontoth_cpp-coding-learnprogramming-activity-6987457184334807040-eBZK (my old post on void* type erasure).
simple, though powerful, useful and important
I've been looking for a way to do this at compile time using templates but haven't found a solution. Is such a thing possible?
With templates you don't get a common type.
Typically that means that at some point you will need some form of type erasure to stop the propagation of the templates.
If your goal is to get rid of the virtual methods, it is achievable: https://www.linkedin.com/posts/simontoth_cpp-coding-learnprogramming-activity-6987457184334807040-eBZK (my old post on void* type erasure).