C++ Logo

sg10

Advanced search

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

From: Gabriel Dos Reis <gdr_at_[hidden]>
Date: Mon, 8 Jun 2020 21:48:52 +0000


| -----Original Message-----
| From: Ville Voutilainen <ville.voutilainen_at_gmail.com>
| Sent: Monday, June 8, 2020 2:19 PM
| To: Richard Smith <richardsmith_at_[hidden]om>
| Cc: sg10_at_[hidden]; Marek Polacek <polacek_at_redhat.com>;
| core_at_[hidden]; Gabriel Dos Reis <gdr_at_microsoft.com>
| Subject: Re: [SG10] [isocpp-core] Feature-test macro for ADL calls with
| template arguments?
|
| On Tue, 9 Jun 2020 at 00:01, Richard Smith <richardsmith_at_google.com>
| wrote:
| > I thought the usual way you write ADL-only calls is
| >
| > template<typename T> void f(T t) {
| > using somewhere::name;
| > name(t); // ADL-only call with fallback to somewhere::name
| > }
|
| The "name" in this case is "get", and it needs to be called with a
| numeric template argument.
|
| > (eg, this is how I think we would recommend that people call 'begin' and
| 'end': "using std::begin; begin(x);"). I think that works equally well if
| 'somewhere' contains a function template, even if you don't have anything
| to put in namespace 'somewhere':
| >
| > namespace somewhere {
| > template<typename T> void name(...) = delete; // specialization missing
| > }
| > template<typename T> void f(T t) {
| > using somewhere::name;
| > name<int>(t); // ADL-only call with fallback to somewhere::name
| > }
| >
| > This works without a feature test macro, and is more reliable than relying
| on the new feature. (For example, the above pattern is not broken if
| someone incautiously adds a non-function, non-function-template 'name' to
| a scope enclosing 'f', whereas use of the new feature would be broken by
| that.)
|
| All we want is to be able to write QPair<What, Ever> qp; get<1>(qp);
|
| I don't know what that "somewhere" would be, nor do I know why I'd
| write a using-declaration for somewhere::get.

For the configuration of Qt that does not use namespaces, there is no "somewhere"; name lookup just finds it.

-- Gaby

Received on 2020-06-08 16:52:02