que*_*en3 2 c++ gcc stl stdmap visual-c++
如果地图中只有单个元素,那么std :: map iterator会减少什么返回?这是示例代码
#include <map>
#include <stdio.h>
int main()
{
std::map<int, int> m;
m.insert(std::make_pair(1, 1));
//std::map<int, int>::iterator it = m.begin();
std::map<int, int>::iterator it = m.upper_bound(0);
printf("isbegin: %d\n", it == m.begin());
--it;
bool isend = it == m.end();
printf("isend: %d\n", isend);
}
Run Code Online (Sandbox Code Playgroud)
在Windows上它将打印isend:1,在Linux上使用g ++ 4.6它将打印isend:0.
问题:上面的减量真的是UB的情况吗?如果没有,那么结果是正确的 - Windows还是Linux?
更新:修改代码以显示调用upper_bound
| 归档时间: |
|
| 查看次数: |
4079 次 |
| 最近记录: |