Date: Mon, 8 Jun 2020 14:01:48 -0700
On Mon, Jun 8, 2020 at 1:35 PM Ville Voutilainen via SG10 <
sg10_at_[hidden]> wrote:
> On Mon, 8 Jun 2020 at 23:30, Gabriel Dos Reis via SG10
> <sg10_at_[hidden]> wrote:
> >
> > At the time, I think I would have thought one was not needed, but that
> could be wrong.
> >
> >
> >
> > Indeed, this sounds to be like an overkill application of feature test
> macros, but…
>
> Well, this macro gives users with the use case I depicted some more
> choices:
> 1) use a work-around that is just.. ..ghastly
> 2) provide an ADL-only customization point if and only if it can be
> written without ghastliness
> 3) just provide a customization point that is not ADL-only
> 4) do (1) or (3) if (2) is not available
>
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
}
(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.)
sg10_at_[hidden]> wrote:
> On Mon, 8 Jun 2020 at 23:30, Gabriel Dos Reis via SG10
> <sg10_at_[hidden]> wrote:
> >
> > At the time, I think I would have thought one was not needed, but that
> could be wrong.
> >
> >
> >
> > Indeed, this sounds to be like an overkill application of feature test
> macros, but…
>
> Well, this macro gives users with the use case I depicted some more
> choices:
> 1) use a work-around that is just.. ..ghastly
> 2) provide an ADL-only customization point if and only if it can be
> written without ghastliness
> 3) just provide a customization point that is not ADL-only
> 4) do (1) or (3) if (2) is not available
>
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
}
(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.)
Received on 2020-06-08 16:05:12