Argument dependent name lookup
Encyclopedia
|
| Tutorials | Encyclopedia | Dictionary | Directory |
|
Argument dependent name lookup
In the C++ programming language, Koenig lookup, also known as argument dependent lookup (ADL), or argument dependent name lookup, applies to the lookup of an unqualified function name depending on the types of the arguments given to the function call. This behavior is named after Andrew Koenig. In Koenig lookup, other namespaces not considered during normal lookup may be searched. The set of namespaces to be searched depends on the types of the function arguments. For a class A, there is a set of associated classes which make up its direct and indirect base classes. The set of associated namespaces for A is the namespace that contains A together with the namespaces containing A's associated classes. It is this set of associated namespaces that is searched for a function with an argument of type A. If the normal lookup of the unqualified name finds a class member function, then Koenig lookup does not occur. Otherwise, the set of declarations found by lookup is the union of the declarations found by normal lookup with the declarations found by looking in the set of associated namespaces. The canonical example of Koenig lookup looks like this: A common pattern in the Standard Template Library is to declare overloaded operators that will be found in this manner. For example, this simple Hello World program would not compile if it weren't for Koenig lookup: Using Note that InterfacesWithin C++, functions found by Koenig lookup are considered part of a class's interface. Within the Standard Template Library, several algorithms make use of unqualified calls to CriticismWhile ADL makes it practical for free functions to be part of the interface of a class, it makes namespaces less strict and so can require the use of fully-qualified names when they would not otherwise be needed. For example, the C++ standard library makes extensive use of unqualified calls to std::swap to swap two values. The idea being that then one can define a specialization of std::swap in their own namespace and it will be used within the STL algorithms. In other words, the behavior of may or may not be the same as the behavior of (where In general, over-dependence on ADL can lead to semantic problems. If one library, External links
Source: Wikipedia | The above article is available under the GNU FDL. | Edit this article
|
|
top
©2008-2009 TutorGig.com. All Rights Reserved. Privacy Statement