Why is std::vector special, and how do proxy references affect generic or concurrent code?
Show answer and explanation
std::vector is a permitted space-optimized specialization that may pack bits instead of storing independent bool objects. Its reference is therefore a proxy that reads or modifies a bit rather than a true bool&, so generic code that assumes T&, takes element addresses, or relies on contiguous bool storage can fail or behave differently. Separate logical elements may share one underlying memory location, making concurrent writes to different bits unsafe without external synchronization. Use it when compact bit storage is intentional; choose bytes, bitset, or a purpose-built concurrent bitmap when ordinary reference or concurrency semantics matter.
std::vector is a permitted space-optimized specialization that may pack bits instead of storing independent bool objects. Its reference is therefore a proxy that reads or modifies a bit rather than a true bool&, so generic code that assumes T&, takes element addresses, or relies on contiguous bool storage can fail or behave differently. Separate logical elements may share one underlying memory location, making concurrent writes to different bits unsafe without external synchronization. Use it when compact bit storage is intentional; choose bytes, bitset, or a purpose-built concurrent bitmap when ordinary reference or concurrency semantics matter.
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.