Thread overview | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
January 22, 2012 Aliasing of template results | ||||
---|---|---|---|---|
| ||||
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
|
January 22, 2012 Re: Aliasing of template results | ||||
---|---|---|---|---|
| ||||
Posted in reply to Alex Rønne Petersen | 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. |
January 22, 2012 Re: Aliasing of template results | ||||
---|---|---|---|---|
| ||||
Posted in reply to Alex Rønne Petersen | 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.
|
January 22, 2012 Re: Aliasing of template results | ||||
---|---|---|---|---|
| ||||
Posted in reply to Denis Shelomovskij | On 01/22/2012 07:07 PM, Denis Shelomovskij wrote:
> 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.
That is actually how it works in Pascal.
|
January 22, 2012 Re: Aliasing of template results | ||||
---|---|---|---|---|
| ||||
Posted in reply to Denis Shelomovskij | On 22-01-2012 19:07, Denis Shelomovskij wrote: > 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. This was exactly my thought too. -- - Alex |
January 22, 2012 Re: Aliasing of template results | ||||
---|---|---|---|---|
| ||||
Posted in reply to Alex Rønne Petersen | 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. |
January 22, 2012 Re: Aliasing of template results | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | 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 |
January 22, 2012 Re: Aliasing of template results | ||||
---|---|---|---|---|
| ||||
Posted in reply to Alex Rønne Petersen | If you know about eponymous templates then it makes sense imo. |
January 22, 2012 Re: Aliasing of template results | ||||
---|---|---|---|---|
| ||||
Posted in reply to Timon Gehr | 22.01.2012 22:11, Timon Gehr пишет:
> On 01/22/2012 07:07 PM, Denis Shelomovskij wrote:
>> 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.
>
> That is actually how it works in Pascal.
You get the point! As Russel Winder wrote in sqrt(2) discussion:
>>dsimcha wrote:
>>LOL and Pascal was my example of a bondage-and-discipline language.
>>...
>Bondage. Discipline. Does this mean Lady Heather will take control?
|
January 23, 2012 Re: Aliasing of template results - alias bar = foo | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic Attachments: | 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.
|
Copyright © 1999-2021 by the D Language Foundation