Multiple ChoiceHard 45s
std::function type-erasure overhead
Compared to a captureless lambda or a template functor, `std::function<Sig>` typically adds:
Options
- 1Type erasure cost: a possible heap allocation for large captures and an indirect (non-inlined) call.
- 2No overhead at all; the target is fully inlined in all implementations and no indirection is introduced.
- 3An extra vtable pointer but no possibility of allocation, since the target is always stored inline.
- 4A reference count with atomic increments on every call, so invocation is never lock-free or allocation-free.
Think you can answer under pressure?
Get matched and answer live questions in 3-minute 1v1 battles. Elo ranking, badge tiers and bragging rights on the line.