What does C++'s zero-overhead principle actually claim, and when can an abstraction still impose runtime or code-size cost?
Show answer and explanation
The zero-overhead principle is a design aim: facilities a program does not use should not impose cost, and an abstraction that is used should be implementable about as efficiently as a reasonable hand-written equivalent with the same semantics. It is not a promise that every abstraction is free. Dynamic allocation, reference counting, synchronization, virtual dispatch, exception metadata, bounds policies, lost optimization opportunities, and many template instantiations can all have required or implementation-dependent costs. Choose semantics first, keep ownership visible, then measure runtime, memory, and binary size on the target before replacing a clear abstraction.
The zero-overhead principle is a design aim: facilities a program does not use should not impose cost, and an abstraction that is used should be implementable about as efficiently as a reasonable hand-written equivalent with the same semantics. It is not a promise that every abstraction is free. Dynamic allocation, reference counting, synchronization, virtual dispatch, exception metadata, bounds policies, lost optimization opportunities, and many template instantiations can all have required or implementation-dependent costs. Choose semantics first, keep ownership visible, then measure runtime, memory, and binary size on the target before replacing a clear abstraction.
Connect the conclusion directly to the type, lifetime, ownership, overload-resolution rule, or library contract present in the question. State implementation dependence or a violated precondition explicitly instead of merely guessing output.