Home
Code-Blog
Projects
Twitter
Blog
Links / Books
About
|
Websites |
Using the Koenig lookup - Argument dependent name lookup (ADL)The Koenig lookup or Argument dependent name lookup (ADL), can be used in many situations.
I am going to show one example that I think in quite useful. template<class T> class X { T m_value; friend std::ostream & operator << (std::ostream &os, const X & x) { os << x.m_value; return os; } friend void swap(X &a, X & b) { X temp(b); a = b; b = temp; } public: X(const T& v) : m_value(v){} }; int main() { X<double> x(2.3); cout << x; X<double> y(1); swap(x, y); std::swap(x,y); // compare with this one.. }
|