C++ 在c+中查找函数+&书信电报;算法>;

C++ 在c+中查找函数+&书信电报;算法>;,c++,stl,find,C++,Stl,Find,我在Ubuntu 18.04.2 LTS上使用g++7.4.0 我想我发现了一个bug: vector<int> a(10,1); vector<int>::iterator it = find(a.begin()+6,a.begin()+3,8); if(it != a.end()) cout<<"FOUND"<<endl; 应该找不到吗?我还发现: it = a.begin()+3 不,这不是一个错误。它完全符合标准定义: 从 设E为: -

我在Ubuntu 18.04.2 LTS上使用g++7.4.0

我想我发现了一个bug:

vector<int> a(10,1);
vector<int>::iterator it = find(a.begin()+6,a.begin()+3,8);
if(it != a.end()) cout<<"FOUND"<<endl;
应该找不到吗?我还发现:

it = a.begin()+3

不,这不是一个错误。它完全符合标准定义:

设E为:
-
*i==value
用于
查找

返回:范围[
first
last
)中E为
true
的第一个迭代器
i
。如果未找到此类迭代器,则返回
last


由于[
a.begin()+6
a.begin()+3
)范围内没有
*i==8
为真的迭代器
i
std::find
返回
a.begin()+3

如果
第一个>最后一个
,这是未定义的行为吗?@Kevin我找不到任何前提条件来说明这一点。它完全可能在那里,我错过了它。所以中的算法是错误的?它应该是
while(first
而不是
while(first!=last)
@Duy它返回范围
[first,last)
中的第一个迭代器。find的迭代器是\u InputI迭代器,只能进行相等比较。因为您的范围是相反的(其中lastit = a.begin()+3