digitalmars.D - Aliasing of template results
- =?ISO-8859-1?Q?Alex_R=F8nne_Petersen?= (21/21) Jan 22 2012 Hi,
- sclytrack (3/22) Jan 22 2012 https://github.com/PhilippeSigaud/D-templates-tutorial
- Denis Shelomovskij (4/23) Jan 22 2012 I like this `alias T template;` syntax.
- Timon Gehr (2/33) Jan 22 2012 That is actually how it works in Pascal.
- Denis Shelomovskij (2/40) Jan 22 2012
- =?UTF-8?B?QWxleCBSw7hubmUgUGV0ZXJzZW4=?= (4/35) Jan 22 2012 This was exactly my thought too.
- Andrej Mitrovic (11/11) Jan 22 2012 A while ago there was a suggestion by Andrei to incorporate this sort of...
- =?ISO-8859-1?Q?Alex_R=F8nne_Petersen?= (4/15) Jan 22 2012 It still feels wrong. Why am I overwriting an existing symbol?
- Andrej Mitrovic (1/1) Jan 22 2012 If you know about eponymous templates then it makes sense imo.
- Manu (13/32) Jan 25 2012 Was it me that raised this on IRC? I've also been discussing it on IRC t...
- Nick Treleaven (5/16) Jan 23 2012 I think this is not really relevant to the OP question about changing
- Denis Shelomovskij (3/14) Jan 24 2012 Personally I don't like current Eponymous Template syntax. I have no
- Jesse Phillips (9/18) Jan 23 2012 Isn't alias this basically what is happening?
- Denis Shelomovskij (3/22) Jan 24 2012 Added issue inspired by your post:
Hi, Someone on IRC wanted to know the element type of an array type and the following code was suggsted: template ElementType(T : T[]) { alias T ElementType; } He was confused about how ElementType!(int[]) could possibly equal int, until we explained that the alias does, in fact, represent the 'result' of the template. So we started discussing whether a more intuitive syntax could be found. Someone suggsted: template ElementType(T : T[]) { alias T template; } I personally believe this makes it perfectly clear that you're aliasing the template itself to T. Thoughts? -- - Alex
Jan 22 2012
On 01/22/2012 03:51 PM, Alex Rønne Petersen wrote:Hi, Someone on IRC wanted to know the element type of an array type and the following code was suggsted: template ElementType(T : T[]) { alias T ElementType; } He was confused about how ElementType!(int[]) could possibly equal int, until we explained that the alias does, in fact, represent the 'result' of the template. So we started discussing whether a more intuitive syntax could be found. Someone suggsted: template ElementType(T : T[]) { alias T template; } I personally believe this makes it perfectly clear that you're aliasing the template itself to T. Thoughts?https://github.com/PhilippeSigaud/D-templates-tutorial BaseElementType maybe. I've just scan-read it.
Jan 22 2012
22.01.2012 18:51, Alex Rønne Petersen пишет:Hi, Someone on IRC wanted to know the element type of an array type and the following code was suggsted: template ElementType(T : T[]) { alias T ElementType; } He was confused about how ElementType!(int[]) could possibly equal int, until we explained that the alias does, in fact, represent the 'result' of the template. So we started discussing whether a more intuitive syntax could be found. Someone suggsted: template ElementType(T : T[]) { alias T template; } I personally believe this makes it perfectly clear that you're aliasing the template itself to T. Thoughts?I like this `alias T template;` syntax. `alias T ElementType;` is like writing `myFunction = value;` in function `myFunction` instead of `return` statement.
Jan 22 2012
On 01/22/2012 07:07 PM, Denis Shelomovskij wrote:22.01.2012 18:51, Alex Rønne Petersen пишет:That is actually how it works in Pascal.Hi, Someone on IRC wanted to know the element type of an array type and the following code was suggsted: template ElementType(T : T[]) { alias T ElementType; } He was confused about how ElementType!(int[]) could possibly equal int, until we explained that the alias does, in fact, represent the 'result' of the template. So we started discussing whether a more intuitive syntax could be found. Someone suggsted: template ElementType(T : T[]) { alias T template; } I personally believe this makes it perfectly clear that you're aliasing the template itself to T. Thoughts?I like this `alias T template;` syntax. `alias T ElementType;` is like writing `myFunction = value;` in function `myFunction` instead of `return` statement.
Jan 22 2012
22.01.2012 22:11, Timon Gehr пишет:On 01/22/2012 07:07 PM, Denis Shelomovskij wrote:You get the point! As Russel Winder wrote in sqrt(2) discussion:22.01.2012 18:51, Alex Rønne Petersen пишет:That is actually how it works in Pascal.Hi, Someone on IRC wanted to know the element type of an array type and the following code was suggsted: template ElementType(T : T[]) { alias T ElementType; } He was confused about how ElementType!(int[]) could possibly equal int, until we explained that the alias does, in fact, represent the 'result' of the template. So we started discussing whether a more intuitive syntax could be found. Someone suggsted: template ElementType(T : T[]) { alias T template; } I personally believe this makes it perfectly clear that you're aliasing the template itself to T. Thoughts?I like this `alias T template;` syntax. `alias T ElementType;` is like writing `myFunction = value;` in function `myFunction` instead of `return` statement.dsimcha wrote: LOL and Pascal was my example of a bondage-and-discipline language. ...Bondage. Discipline. Does this mean Lady Heather will take control?
Jan 22 2012
On 22-01-2012 19:07, Denis Shelomovskij wrote:22.01.2012 18:51, Alex Rønne Petersen пишет:This was exactly my thought too. -- - AlexHi, Someone on IRC wanted to know the element type of an array type and the following code was suggsted: template ElementType(T : T[]) { alias T ElementType; } He was confused about how ElementType!(int[]) could possibly equal int, until we explained that the alias does, in fact, represent the 'result' of the template. So we started discussing whether a more intuitive syntax could be found. Someone suggsted: template ElementType(T : T[]) { alias T template; } I personally believe this makes it perfectly clear that you're aliasing the template itself to T. Thoughts?I like this `alias T template;` syntax. `alias T ElementType;` is like writing `myFunction = value;` in function `myFunction` instead of `return` statement.
Jan 22 2012
A while ago there was a suggestion by Andrei to incorporate this sort of syntax: template ElementType(T : T[]) { alias ElementType = T; } struct Foo(T) { alias Type = T; } I think people agreed it was a nice syntax, but I don't know if anyone tried to implement it.
Jan 22 2012
On 22-01-2012 19:33, Andrej Mitrovic wrote:A while ago there was a suggestion by Andrei to incorporate this sort of syntax: template ElementType(T : T[]) { alias ElementType = T; } struct Foo(T) { alias Type = T; } I think people agreed it was a nice syntax, but I don't know if anyone tried to implement it.It still feels wrong. Why am I overwriting an existing symbol? -- - Alex
Jan 22 2012
If you know about eponymous templates then it makes sense imo.
Jan 22 2012
On 22 January 2012 20:36, Alex R=C3=B8nne Petersen <xtzgzorex gmail.com> wr= ote:On 22-01-2012 19:33, Andrej Mitrovic wrote:Was it me that raised this on IRC? I've also been discussing it on IRC the last few days, and it is very confusing. I can write code that works now, but I still for the life of me find coherent logic for the syntax in my head, and whether I'm aliasing something, or producing a constant using enum... one way I'm producing a type, the other way I'm producing a value. The same syntax can produce this disconnected result; feels very unnatural to me. Types and values feel like totally different things in my mind, perhaps this is my error? I think the problem for me is that I can't see clearly exactly what a template actually does, it feels like there's some magic involved, mainly in the result syntax, that makes it work somehow...A while ago there was a suggestion by Andrei to incorporate this sort of syntax: template ElementType(T : T[]) { alias ElementType =3D T; } struct Foo(T) { alias Type =3D T; } I think people agreed it was a nice syntax, but I don't know if anyone tried to implement it.It still feels wrong. Why am I overwriting an existing symbol?
Jan 25 2012
On 22/01/2012 18:33, Andrej Mitrovic wrote:A while ago there was a suggestion by Andrei to incorporate this sort of syntax: template ElementType(T : T[]) { alias ElementType = T; } struct Foo(T) { alias Type = T; } I think people agreed it was a nice syntax, but I don't know if anyone tried to implement it.I think this is not really relevant to the OP question about changing eponymous template syntax though. By coincidence, I implemented 'alias bar = foo;' syntax yesterday in my local copy - see attached diff.
Jan 23 2012
22.01.2012 22:33, Andrej Mitrovic пишет:A while ago there was a suggestion by Andrei to incorporate this sort of syntax: template ElementType(T : T[]) { alias ElementType = T; } struct Foo(T) { alias Type = T; } I think people agreed it was a nice syntax, but I don't know if anyone tried to implement it.Personally I don't like current Eponymous Template syntax. I have no claim to Alias syntax.
Jan 24 2012
On Sunday, 22 January 2012 at 14:51:36 UTC, Alex Rønne Petersen wrote:So we started discussing whether a more intuitive syntax could be found. Someone suggsted: template ElementType(T : T[]) { alias T template; } I personally believe this makes it perfectly clear that you're aliasing the template itself to T. Thoughts?Isn't alias this basically what is happening? template ElementType(T : T[]) { alias T this; } Aliasing this template to type T? Ok, since multiple alias this are technically allowed... but still...
Jan 23 2012
22.01.2012 18:51, Alex Rønne Petersen пишет:Hi, Someone on IRC wanted to know the element type of an array type and the following code was suggsted: template ElementType(T : T[]) { alias T ElementType; } He was confused about how ElementType!(int[]) could possibly equal int, until we explained that the alias does, in fact, represent the 'result' of the template. So we started discussing whether a more intuitive syntax could be found. Someone suggsted: template ElementType(T : T[]) { alias T template; } I personally believe this makes it perfectly clear that you're aliasing the template itself to T. Thoughts?Added issue inspired by your post: http://d.puremagic.com/issues/show_bug.cgi?id=7364
Jan 24 2012