对于任何空()向量,begin()== end()? [英] Is begin() == end() for any empty() vector?

查看:945
本文介绍了对于任何空()向量,begin()== end()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我长期以来认为任何空 std :: vector V V.begin V.end()。然而我在C ++规范中没有看到这一点,这总是

解决方案

是的,这是标准要求的

§23.2.1 C ++ 11标准的表96说:

  + ---------- + ----- ---------- + ---------------------- + 
|表达式|返回类型|操作语义|
| ---------- | --------------- | ------------------ ---- |
| a.empty()| Convertible | a.begin()== a.end()|
| | to bool | |
| | | |
+ --------------------------------------------- ---- +


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

这篇关于对于任何空()向量,begin()== end()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆