C++ Logo

SG10

Advanced search

Subject: Re: [isocpp-core] Feature-test macro for ADL calls with template arguments?
From: Ville Voutilainen (ville.voutilainen_at_[hidden])
Date: 2020-06-08 18:34:41


On Tue, 9 Jun 2020 at 02:29, Richard Smith <richardsmith_at_[hidden]> wrote:
>> I don't know what that "somewhere" would be, nor do I know why I'd
>> write a using-declaration for somewhere::get.
>
>
> Consider:
>
> // user.h
> struct get {};
>
> // user.cc
> #include "user.h"
> #include <QPair>
>
> That won't compile with your above approach. Unqualified lookup for 'get' finds the user's struct ::get, so ADL is not performed. Adding the using-declaration fixes the problem:

Sure, I understood what you meant before.

>
> // QPair
> namespace detail {
> template<int> void get(...) = delete;
> }
> void whatever() {
> using detail::get; // add this to fix the problem
> QPair<What, Ever> qp;
> get<1>(qp); // ::get not found by unqualified lookup, so ADL is performed now
> }
>
> If you have some default implementation of 'get' (such as a general unspecialized one), then you could 'using' that instead of using a placeholder one like detail::get.

Right; I have no intention of forcing my users or recommending that
anyone else forces their users
to write a using-declaration whenever they want to use a tuple-like
interface on their types, even if it
can sometimes theoretically clash with namespace-scope non-functions.

We have a language fix that makes hidden friend templates work with
ADL when template arguments are provided
for a call. We have work-arounds that don't come even close to
achieving the same functionality. It would seem
rather reasonable to allow programmers to detect when they can use the
new superior functionality.


SG10 list run by sg10-owner@lists.isocpp.org