我注意到整数上std::max_element的一种奇怪行为,它们的差异不超过一个:
#include <iostream>
#include <algorithm>
#include <vector>
int main()
{
std::vector<int> v = {1, 2, 3};
std::cout<<*std::max_element(v.begin(), v.end())<<"\n";//it's ok - correct answer
std::cout<<*std::max_element(v.begin(), v.begin()+1)<<"\n";//compare between 1 and 2: answer - 1
std::cout<<*std::max_element(v.begin()+1, v.begin()+2)<<"\n";//compare between 2 and 3: answer - 2
}
我在64 位 linux上使用gcc 4.8编译器。这是编译器的错误,还是其他?