Continued from Argument Dependent Lookup (ADL).
To suppress ADL, we surround the function call in parenthesis. Consider the following example.
namespace my {
template <typename RandomIt>
void sort(RandomIt begin, RandomIt end) {
// Doing a merge sort, then call sort recursively
sort(begin, mid);
}
}
The recursive call to sort is ambiguous when a vector’s iterators are given as ADL also gives std::sort
. To fix it, change the call to (sort)(begin, mid)
. This suppresses ADL.