libc++: Maximum size of a std::vector


I am puzzled by the result of std::vector::max_size() on the n = 32 and n = 64 bits system I have tested. The result is 2^n − 1. Let me explain why I am puzzled.

Every implementation of std::vector that I know of, libc++ included, has three members of type T*: begin_, end_, capacity_. begin_ points to the first value of the vector and end_ points to the one after the last. The size() method is computes end_ - begin_. But the result of this difference is of type std::ptrdiff_t which is a signed integer of n bits on every implementation that I know of. Therefore, this type can not store the integer 2^n − 1, but only up to 2^(n − 1) − 1.

I would expect this last number for max_size(). Is it a bug or something that I overlooked?