Let's consider such code:
#include <vector>
int main() {
vector<int> v = {1, 2, 3};
return 0;
}
GCC 6.3 doesn't compile it with error: ‘vector’ was not declared in this scope
- great, I'd expect that. I need to write std::vector
to compile, good.
However, the following does compile:
#include <vector>
#include <algorithm>
int main() {
std::vector<int> v = {1, 2, 3};
int c = count(v.begin(), v.end(), 2);
return 0;
}
It looks like count
is imported into global namespace. I also tried find
- the same.
Why #include <algorithm>
imports names into global namespace? Which C++ Standard Library headers do this and which not?