Developing the idea of
caching the result of calculations of heavy functions
, I propose to write a small template class, which will take the function as an argument, namely the lambda function, as the most universal an instrument within which a heavy function will be performed.
In this case, the result of the function will not be calculated at the time of creation of the Functor, but at the time of calling the operator parentheses
. And at the same time, the result will be cached. That will allow not to call a heavy function more than once as part of the execution of a method.