std::vector
Despite breaking multiple assumptions that hold for every other std::vector
Consider the following example:
#include
#include
int main() {
std::vector\ v = { true, false, true };
bool\* p = &v\[0\]; // error: not a bool\*
}
Unlike other std::vector
- does not store actual bool objects
- does not provide a real bool*
- returns a proxy object instead of a reference from operator[]
As a result, it violates expectations such as:
- taking the address of elements
- pointer-based APIs
- treating it as a normal contiguous container
My questions are:
1. What was the original design motivation for std::vector
2. What exact guarantees does the C++ standard provide for std::vector
3. Which common, seemingly reasonable assumptions about std::vector
4. In modern C++ (C++20/23), what are the recommended alternatives, and in which cases—if any—is std::vector
I am specifically looking for standard references, committee rationale, and historical context—not general advice like “don’t use std::vector