Jump to content

Featured Replies

Posted

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;
}

View the full article

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

Recently Browsing 0

  • No registered users viewing this page.