Why is std::vector<bool> special, and what guarantees does it actually provide?
16:41 24 Dec 2025

std::vector is the only standard container whose name strongly suggests “a vector of bool”, yet it intentionally does not model a contiguous container of bool objects.

Despite breaking multiple assumptions that hold for every other std::vector, it remains standardized and unchanged for decades.

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 specializations, 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, and what constraints led to this specialization?

2. What exact guarantees does the C++ standard provide for std::vector, and which guarantees of std::vector explicitly do not apply?

3. Which common, seemingly reasonable assumptions about std::vector are invalid for std::vector?

4. In modern C++ (C++20/23), what are the recommended alternatives, and in which cases—if any—is std::vector still the correct or intended choice?

I am specifically looking for standard references, committee rationale, and historical context—not general advice like “don’t use std::vector”.

c++ vector stl containers stdvector