top | item 29538508

(no title)

mhogomchungu | 4 years ago

Problems with std::function:-

1. It can not hold move only callable objects.

2. It heap allocate stored callable object if the object is large enough.

discuss

order

nly|4 years ago

3. Type-erased (its primary use case, but hinders optimization)

4. Can't be constexpr

tcbawo|4 years ago

Also, std::functions are not comparable. This makes it harder to use for registration/de-registration or an Observer architecture.

pvarangot|4 years ago

I think lambdas also heap allocate, at least on embedded C++11/14 projects I remember having to have a little of heap for them.

stargrazer|4 years ago

Can you point to better alternate ways or idioms?