DIP 1023--Resolution of Template Alias Formal Parameters in Template Functions--Community Review Round 1
Stefanos Baziotis
sdi1600105 at di.uoa.gr
Tue Sep 10 21:48:33 UTC 2019
On Tuesday, 10 September 2019 at 14:06:10 UTC, jmh530 wrote:
> On Friday, 6 September 2019 at 12:58:33 UTC, Stefanos Baziotis
> wrote:
>> Thanks Mike and jmh530.
>>
>> [snip]
>
> I'm sure I could find some way to simplify this what's below,
> but I've just been thinking about Atila's concepts library and
> it's interaction with this DIP [1]. Removing the
> concepts-specific part of it, it becomes
>
> void checkFoo(T)()
> {
> T t = T.init;
> t.foo();
> }
>
> enum isFoo(T) = is(typeof(checkFoo!T));
>
> struct Foo
> {
> void foo() {}
> }
>
> I'm curious if this DIP is accepted could something like the
> following work
>
> template Foo_able(T)
> if (isFoo!T)
> {
> alias Foo_able = T;
> }
>
> void useFoo(T)(auto ref Foo_able!T x) {
>
> }
>
> void main() {
> Foo x;
> useFoo(x);
> }
>
> Right now, to get it to work would require writing
> useFoo!Foo(x) because the Foo is not detected to be a
> Foo_able!T.
>
> If something like the above works under this DIP, while I grant
> I don't think that this resolves all of the issues that the
> concepts library tries to address, I think it would be a win
> for readability.
>
TBH, I did not understand completely the code. From what I can
tell,
this DIP doesn't have connection with the code above because
there's no alias. But this might be an oversimplification and
I might have missed something.
>
> The big thing that the concepts library provides over what is
> above is improved error messages (as of now, it is just a
> replacement of the template constraint). It tells you why the
> argument does not fit. It seems like if the alias is
> transformed to something like below, still using the concepts
> library, then it you would still be able to get the improved
> error messages. You wouldn't need to apply the models UDA to
> the struct in this case in order to get the good error messages.
>
> template Foo_able(T)
> {
> static assert(models!(T, isFoo));
> alias Foo_able = T;
> }
Again, sorry for not understanding. I'm not familiar with the
concepts library.
From what I can tell, this again has no connection with the DIP.
The alias
is not a template alias and it's not used as a function argument.
- Stefanos
More information about the Digitalmars-d
mailing list