Skip to content

Comment on The Functor Pattern in C++parent

Comments

If only it didn’t use dynamic allocation…ah well. The value is worth the cost.

I don't think std::function does any dynamic allocation when you initialize it with simple functions. When you initialize it with function objects or lambda expression, most, if not all implementations use the small object optimization to avoid dynamic allocation when possible.

With function objects the GNU std::function does do dynamic allocation. Even for objects as small as an empty struct.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.