ADL – Avoid Debugging Later -- Coral Kashri

kashri-adl.pngBack in the day, being a witch was considered a grave crime. Today, we’re diving into one of C++’s lesser-known spells: ADL (Argument-Dependent Lookup). 

ADL – Avoid Debugging Later

by Coral Kashri

From the article:

But before we explore this arcane magic, you must heed a warning—black magic comes with consequences. ADL is particularly treacherous, often leading to frustrating and hard-to-debug issues. Whenever possible, it’s wise to avoid casting this spell unless absolutely necessary.

Ingredients

Every spell needs ingredients, this time the only ingredients you need are a C++ compiler and a function that accepts at least one parameter, but there is a try catch, the parameter type has to belong to the same namespace of the function.

This spell works in shadows—you must look closely to uncover its effect.

std::cout << "Can you see me?";

Should the spell have passed you by, I’ll summon its power again for your eyes:

std::vector<int> a{1}, b{2};
swap(a, b);

If the spell’s effect remains elusive, let’s summon the entire code for you to see:

#include <vector>

int main() {
    std::vector<int> a{1}, b{2};
    swap(a, b);
    return 0;
}

Add a Comment

Comments are closed.

Comments (0)

There are currently no comments on this entry.