I have long assumed that for any empty std::vector
V, V.begin() == V.end()
. Yet I see nothing in the C++ specification that states this to always be true. Is it necessarily true or does it just happen to be true on most implementations?
I have long assumed that for any empty std::vector
V, V.begin() == V.end()
. Yet I see nothing in the C++ specification that states this to always be true. Is it necessarily true or does it just happen to be true on most implementations?
Yes, that's what the standard requires it to be for empty()
for any container.
§ 23.2.1 Table 96 of the C++11 standard says:
+----------+---------------+----------------------+
|Expression| Return Type | Operational Semantics|
|----------|---------------|----------------------|
|a.empty() |Convertible |a.begin() == a.end() |
| |to bool | |
| | | |
+-------------------------------------------------+