Perhaps you are looking for a team implementation in Modern C ++ Design.
The boost :: function has as much overhead as needed to do what it does. The goal is to allow you to pass a "pointer" to any function that can respond to its interface. If you do not need this behavior, then these overheads are real costs. If you do this, I honestly don't see a better approach than boost :: function (itโs even optimized to make sure you donโt get a bunch of extra memory usage from virtual functions in some implementations).
You can build a method that will lead to possible inline code, but as soon as you try to save it in a common interface, you will get a boost :: function bonus (possibly more).
What I would recommend is to simply use boost :: function until you find that you really need to replace something faster. Then, and only then do you write the material of the template of varying complexity to make this happen.
Just saving the boost :: function may be sufficient for what you need. You can also see boost :: signals.
source share