Posted February 11Feb 11 Back 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.