[DIP] Resolution of Alias Template Parameters in Function Templates
Stefanos Baziotis
sdi1600105 at di.uoa.gr
Mon May 20 17:36:35 UTC 2019
On Monday, 20 May 2019 at 14:45:59 UTC, jmh530 wrote:
>
> Hmm, the link to the DIP isn't working for me now.
>
Yes, I updated it yesterday, please use this link:
https://github.com/baziotis/DIPs/blob/master/Drafts/1NNN-SB.md
>
> My rationale would be that, from a generic code perspective, it
> is very helpful if alias templates behave like aliases
> (including both is expressions and use in functions). There may
> be good reasons why that shouldn't or can't be the case, but I
> think the goal should be on allowing for the most generic code
> possible.
>
I agree, but with the current proposal, they do behave like
aliases in that,
there is no distinction between the true type and the alias.
Here is an example similar to yours above:
alias Num = int;
auto foo(T)(T m)
{
import std.stdio : writeln;
static if (is(T : int)) {
writeln("here");
} else static if (is(T : Num)) {
writeln("there");
} else {
static assert(0, "should not be here");
}
}
void main()
{
Num x;
int y;
foo(x);
foo(y);
}
Both of them go to "here". The `Num` one does not go to "there".
That is, it can't
be distinguished whether we have an int because of an alias or
because we
actually had an int. And that I understand that it is one of the
important points
of aliases.
Of course, I may have missed / misunderstood something badly in
all of that,
but I understand that distinguishing them (e.g. in your example
above)
makes template aliases different than normal aliases.
More information about the Digitalmars-d
mailing list