Can std::search_n be called "safe" with count 0? In particular, such a code is as follows:
#include <algorithm> #include <cstdio> int main(int argc, char *argv[]) { const int test[7] = {1, 2, 3, 4, 5, 6, 7}; const int *const location = std::search_n(test, test + 7, 0, 8); if (location == test) { std::puts("Found it at the beginning!"); } }
I expect this code to reach the std::puts statement, and most std::search_n descriptions seem to imply that this will happen. However, most of the implementation examples that I find will not. What does the standard say?
c ++ stl-algorithm
Joshua green
source share