C++ Logo

SG10

Advanced search

Subject: Re: [isocpp-core] Feature-test macro for ADL calls with template arguments?
From: John Spicer (jhs_at_[hidden])
Date: 2020-06-08 15:11:38


I don’t recall if a feature test macro was discussed for this.

At the time, I think I would have thought one was not needed, but that could be wrong.

There is a workaround of sorts. If you add any function template with the same name and that will be found by normal lookup, then ADL will be done for the function template call with the explicit argument list.

namespace N {
        struct A { };
        template <typename T>
        T func(const A&) { return T(); }
}
template <class T, int x[-sizeof(T)]> void func(); // something uncallable

void f() {
        N::A a;
        func<int>(a);
}

Which is not to say that we shouldn’t add a macro for this.

John.

> On Jun 8, 2020, at 11:56 AM, Ville Voutilainen via Core <core_at_[hidden]> wrote:
>
> On Mon, 8 Jun 2020 at 18:49, Marek Polacek <polacek_at_[hidden]> wrote:
>>
>> On Mon, Jun 08, 2020 at 12:02:28PM +0300, Ville Voutilainen via Core wrote:
>>> P0846 gives us the ability to do ADL for calls to function templates with
>>> explicit template arguments provided. Did we get a feature-testing macro
>>> for it?
>>
>> Doesn't seem that we have it.
>
> For a rationale to consider having it: I have users who would like to
> write ADL-only structured bindings
> customization points and also allow them to be called with ADL calls;
> library folks call this a "hidden friend".
> When the macro is not defined, the fallback code would expose the
> customization point (or not provide
> it at all), but when it's defined, the customization point would be a
> hidden friend. Structured bindings seem to be able
> to call it anyway, but user code can't, before the language fix is implemented.
> _______________________________________________
> Core mailing list
> Core_at_[hidden]
> Subscription: https://lists.isocpp.org/mailman/listinfo.cgi/core
> Link to this post: http://lists.isocpp.org/core/2020/06/9275.php



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