C++ Logo

sg10

Advanced search

Re: [SG10] [isocpp-core] Feature-test macro for ADL calls with template arguments?

From: Ville Voutilainen <ville.voutilainen_at_[hidden]>
Date: Mon, 8 Jun 2020 23:30:59 +0300
On Mon, 8 Jun 2020 at 23:11, John Spicer <jhs_at_[hidden]> wrote:
>
> 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);
> }

Impressive. :)

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

Not indeed; I would hesitate to recommend such techniques, although
for desperate users, maybe.

Received on 2020-06-08 15:34:55