back_inserter: Why is std:: not required by compiler

I am learning about iterators, I noticed that even though back_inserter is in the std namespace, the following code is allowed by the compiler.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
#include <algorithm>
#include <iterator>
#include <vector>


int main()
{
    std::vector<int> v( 10, 100 );
    std::vector<int> u;
    std::copy( v.begin(), v.end(), back_inserter( u ) );
    std::copy( u.begin(), u.end(), std::ostream_iterator<int>( std::cout, ", " ) );
    return 0;
}


I checked the reference on this site. The example code given also does not mention the std:: scope before back_inserter.
http://www.cplusplus.com/reference/iterator/back_inserter/?kw=back_inserter

Why does compiler omit this? I checked it with pedantic, Wall and ansi switches ON.

Thanks!
Last edited on
Argument-dependent lookup examines the std namespace because the argument u has a type whose definition is located in the std namespace.
http://en.cppreference.com/w/cpp/language/adl
OK, Thanks a lot!
Learnt a new concept (ADL)...
Topic archived. No new replies allowed.