C++ Logo


Advanced search

Subject: Re: [std-proposals] Operator functions to fix ADL
From: Григорий Шуренков (grigorij1981_at_[hidden])
Date: 2020-10-12 11:53:33


> As one of the "I am just a regular user, not a compiler guru" lurkers on
this list, I'd just like to mention that anything that involves call-site
annotation is a great source of confusion for regular users, especially
when the answer to "Why?" is "obscure reason X" as it would be in this
case. Shifting the responsibility to the caller is just as ineffective as
documenting the issue in a manual.

Let me explain why it might be a good idea to have a call-site annotation
for ADL. The reason is not obscure, the annotation designates an unusual
function call - a customization point. Moreover, until recently it was a
recommended practice to annotate such calls in the following way:
using std::swap;
swap(a, b);

it is effectively an annotation, but a strange one, leaving it without
comment would raise a question from a regular user. Now we can write
std::ranges::swap(a, b); of course, however, design of customization points
of std::ranges currently relies on intricacies of ADL name lookup.
So, I would argue that the annotation would be useful in the implementation
of such wrappers as std::ranges::swap, std::ranges::begin etc.

Annotation is not bad, if it actually helps a user to understand that
something unusual is going on, then after consulting language reference or
just google a user can understand what exactly is going on.

Second point is that it would be rare, most of the functions are not
customization points.

Third point is that such annotation allows what is currently not possible.
If you look up the definition of range-based for loop in the standard you'd
see that it is impossible to write its implementation in plain C++. To find
begin and end for a container it performs only ADL w/o usual name lookup.
An annotated call would do exactly that.


STD-PROPOSALS list run by std-proposals-owner@lists.isocpp.org

Standard Proposals Archives on Google Groups