Getting the overload set of a template
Simen Kjærås
simen.kjaras at gmail.com
Mon Apr 23 00:26:23 UTC 2018
On Sunday, 22 April 2018 at 19:27:24 UTC, Alex wrote:
> On Sunday, 22 April 2018 at 18:25:29 UTC, Simen Kjærås wrote:
>> No lowering occurs here. A lowering is when the compiler takes
>> one piece of syntax and replaces it with a different one,
>> usually one that's more verbose.
>>
>> In a way, it's kind of like a template being instantiated, in
>> that you write some code and it's being replaced by something
>> else. It's not, however, the same thing.
>
> So, how to distinguish it?
There is a limited set of lowerings, and they are defined in the
language, not in user code. They include operator overloading
(where `a op b` is translated to `a.opBinary!op(b)`), foreach
over ranges (where `foreach(e; range) { }` becomes `for (auto e =
range.front; !range.empty(); range.popFront()) { }`), string
switching (which is forwarded to a template in druntime), and
more that I can't recall right now. This is compiler magic meant
to make implementating new features and reasoning about existing
features, easier. They are briefly described in the article you
linked, but I agree it offers limited insight. I've not found any
other great sources of information about it, sadly.
> // tuple("Has foo1_A")
> pragma(msg, __traits(getAttributes, foo1!"a"));
> // tuple("Has foo1_A")
> pragma(msg, __traits(getAttributes, foo2!"a"));
> // tuple("Has foo1_B")
> pragma(msg, __traits(getAttributes, foo1!"b"));
> // tuple("Has foo1_B")
> pragma(msg, __traits(getAttributes, foo2!"b"));
You explicitly stated 'uninstantiated template'. These are
instantiated templates.
This seems to indicate that we're talking past each other. I may
have misunderstood what you meant when you wrote "But you won't
be able to get the UDA from an uninstantiated template will
you?", or one of us has misunderstood some other part of the
discussion.
--
Simen
More information about the Digitalmars-d-learn
mailing list