Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
144 views
in Technique[技术] by (71.8m points)

c++ - Is begin() == end() for any empty() vector?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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        |                      |
 |          |               |                      |
 +-------------------------------------------------+

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...