May 4, 2014 at 12:10pm UTC
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 May 4, 2014 at 12:13pm UTC
May 4, 2014 at 12:23pm UTC
OK, Thanks a lot!
Learnt a new concept (ADL)...