Criticism
While ADL makes it practical for functions defined outside of a class to behave as if they were part of the interface of that 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 is that then one can define an own version of std::swap in one's own namespace and it will be used within the STL algorithms. In other words, the behavior of
std::swap(a, b);may or may not be the same as the behavior of
using std::swap; swap(a, b);(where a
and b
are of type N::A
) because if N::swap(N::A&, N::A&)
exists, the second of the above examples will call it while the first will not. Furthermore, if for some reason both N::swap(N::A&, N::A&)
and std::swap(N::A&, N::A&)
are defined, then the first example will call std::swap(N::A&, N::A&)
but the second will not compile because swap(a, b)
would be ambiguous.
In general, over-dependence on ADL can lead to semantic problems. If one library, L1
, expects unqualified calls to foo(T)
to have one meaning and another library, L2
expects it to have another, then namespaces lose their utility. If, however, L1
expects L1::foo(T)
to have one meaning and L2
does likewise, then there is no conflict, but calls to foo(T)
would have to be fully qualified (i.e. L1::foo(x)
as opposed to using L1::foo; foo(x);
) lest ADL get in the way.
Read more about this topic: Argument-dependent Name Lookup
Famous quotes containing the word criticism:
“The critic lives at second hand. He writes about. The poem, the novel, or the play must be given to him; criticism exists by the grace of other mens genius. By virtue of style, criticism can itself become literature. But usually this occurs only when the writer is acting as critic of his own work or as outrider to his own poetics, when the criticism of Coleridge is work in progress or that of T.S. Eliot propaganda.”
—George Steiner (b. 1929)
“As far as criticism is concerned, we dont resent that unless it is absolutely biased, as it is in most cases.”
—John Vorster (19151983)
“It is the will of God that we must have critics, and missionaries, and Congressmen, and humorists, and we must bear the burden. Meantime, I seem to have been drifting into criticism myself. But that is nothing. At the worst, criticism is nothing more than a crime, and I am not unused to that.”
—Mark Twain [Samuel Langhorne Clemens] (18351910)