C++ Logo

sg10

Advanced search

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

From: Barry Revzin <barry.revzin_at_[hidden]>
Date: Tue, 9 Jun 2020 09:39:11 -0500
On Mon, Jun 8, 2020 at 7:46 PM Ville Voutilainen via Core <
core_at_[hidden]> wrote:

> On Tue, 9 Jun 2020 at 03:38, Richard Smith <richardsmith_at_[hidden]>
> wrote:
> >> >> It would seem
> >> >> rather reasonable to allow programmers to detect when they can use
> the
> >> >> new superior functionality.
> >> > The SG10 policy has historically been to not include a feature test
> macro where there is a simple syntactic alternative that gets you the same
> functionality regardless of compiler support. As far as I'm aware, there
> is, in this case.
> >>
> >> I am yet to see a simple syntactic alternative in this thread. But
> >> well, if this is not a reasonable feature-macro
> >> addition for SG10, then we'll live without it. To me, it seems exactly
> >> the kind of feature-detection use case a feature-testing
> >> macro is good for.
> >
> >
> > Can you give an example of how you'd imagine people using this? If we're
> expecting them to write
> >
> > #ifdef __cpp_something
> > get<1>(qp);
> > #else
> > something_else(qp);
> > #endif
> >
> > instead of, say,
> >
> > using adl::get;
> > get<1>(qp);
> >
> > then it seems to me that the feature test macro doesn't give us
> syntactic simplicity either.
>
> It gives syntactic simplicity at the call site. That matters a
> thousand times more than what the library
> gunk looks like. What I expect/imagine library writers doing is either
>
> struct MyTupleLike {
> ...
> // the definition of get<> as a hidden friend goes here};
> };
>
> #ifndef __cpp_adl_template_call
> // John's work-around goes here
> #endif
>


I guess Qt just needs to make sure that its sufficiently uninvokable get()
in the global namespace doesn't conflict with other libraries that want to
do the same thing. So you could do:

namespace voldemort::qt::lol { class get_tag { explicit get_tag(int); }; }
template <typename T> void get(voldemort::qt::lol::get_tag );

That works with Marc's example (gcc 7.1 and clang 6):
https://godbolt.org/z/NAB3G3 and seems ... rather unlikely ... to conflict
with anything. You could just provide this unconditionally?

Barry

Received on 2020-06-09 09:42:30