http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58358
Bug ID: 58358 Summary: search_n has a Complexxity violation for random access iterator Product: gcc Version: 4.8.1 Status: UNCONFIRMED Severity: minor Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: kariya_mitsuru at hotmail dot com Following code should print less than or equal to 11, but it prints 20. #include <algorithm> #include <vector> #include <iostream> int main() { std::vector<int> a{2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; int count = 0; std::search_n(a.begin(), a.end(), 10, 1, [&count](int t, int u){ ++count; return t == u; }); std::cout << count << std::endl; }