So I was recently writing some code in C++ and came across yet another of C++'s many quirks/pitfalls. This one is called ADL. Argument dependent lookup.
What that means is C++ will sometimes search non-explicitly available namespaces for symbols. I hope you are scratching your head right now. Yes, the whole point of namespaces is to prevent the possibility of namespace collisions. And yes, this "feature" prevents you from trusting namespaces.
From wikipedia here is an example of how this can screw you over:
std::swap(a, b);
...may or may not be the same as the behavior of...
using std::swap;
swap(a, b);
...if in the vastness headers your project includes there is a function called swap, under the "right" conditions it may be used instead of the one you expect.
Yes, there are situations where it is useful. But it pisses me off none-the-less. If you are interested, read the wiki article here:
http://en.wikipedia.org/wiki/Argument_dependent_name_lookup
Sometimes I really hate C++. I hope D will be my savior.
Showing posts with label ADL. Show all posts
Showing posts with label ADL. Show all posts
Thursday, October 25, 2007 at 9:44 PM
(ADL & C++) == sucks
Posted by
Catskul
3
comments
Labels: ADL, c++, D, programming
Subscribe to:
Posts (Atom)