why for_each works without std:: prefix

Viewed 556

What i think is that for_each is defined in standard namespace, but this code actually compiles and runs with the following compiler flags. Can somebody please explain why?

  //@filename myprog.cpp 
  //g++-4.5 --std=c++0x myprog.cpp

  #include<iostream>
  #include<algorithm>

  int main()
  {
    std::vector<int> v{1,2,3,4,5};
    std::cout<<"printing the number\n";
    for_each(v.begin(),v.end(),[](int num) {//no std::for_each
        std::cout<<num<<"\t";
    });
 return 0;
 }
1 Answers
Related