While I was coding I realized I forgot to put std:: in front of my function name. Does anyone know why this actually compiles?
Why does this compile without having to do
std::random_shuffle?
Edit: Changed post to have only minimal code
1 2 3 4 5 6 7 8
|
#include <algorithm>
#include <vector>
int main() {
std::vector<int> v {1, 2, 3, 4};
random_shuffle(v.begin(), v.end());
return 0;
}
|
Last edited on
This is ADL at work. As both parameter are from std namespace compiler looks for that function in std namespace too.
Replace this line with random_shuffle(&v[0], &v[0] + 4);
and it will stop working as arguments are pointers and do not have relaton to any namespace.
Thanks, interesting feature/set of rules.