std::function() is replaced with polymorphic objects allocated on the stack to eliminate dynamic allocations for temporary objects.