Argument dependent lookup

Why does this compile?

A one-liner to print a vector to stdout. But why does this compile without the namespace std::?

#include <iostream>
#include <vector>
#include <iterator>

int main() {

const std::vector<int> v{1, 2, 3, 4, 5};
copy(cbegin(v), cend(v), std::ostream_iterator<int>(std::cout, "n"));

Run the code on Compiler Explorer, Jason Turner on YouTube and ADL on Wikipedia. Note: C++14 is the default for the latest GCC (9.2).


Propose some other examples of ADL.

results matching ""

    No results matching ""