Skip to content

Comment on Why C++ Is Terrifying

Comments

I find it way more annoying that std::function's type erasure--but insistence that it should be copyable--means it isn't able to commit to being movable, and so then simply can't store move-only functions; in practice I simply never want to copy an std::function, yet the type is seemingly crippled to offer that ability :/. Between this issue and how it tends to require memory allocation even in cases of bounded scope, I honestly just find std::function only useful in trivial "toy" code (or where I am going out of my way to use STL for some silly reason)... I have a few type-erasing function wrappers of my own that I use in various projects, and I do live demos for the intro CS classes I help teach wherein I quickly type out new rather-fully-featured replacements, showing the iterative implementation as you need new functionality.

folly::Function was added for exactly this reason I think https://github.com/facebook/folly/blob/master/folly/docs/Fun...

AboutSource Built by g1lg1l

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