Jump to page: 1 2
Thread overview
Aliasing of template results
Jan 22, 2012
sclytrack
Jan 22, 2012
Denis Shelomovskij
Jan 22, 2012
Timon Gehr
Jan 22, 2012
Denis Shelomovskij
Jan 22, 2012
Andrej Mitrovic
Jan 22, 2012
Andrej Mitrovic
Jan 25, 2012
Manu
Re: Aliasing of template results - alias bar = foo
Jan 23, 2012
Nick Treleaven
Jan 24, 2012
Denis Shelomovskij
Jan 23, 2012
Jesse Phillips
Jan 24, 2012
Denis Shelomovskij
January 22, 2012
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
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
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
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
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
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
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
If you know about eponymous templates then it makes sense imo.
January 22, 2012
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
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.


« First   ‹ Prev
1 2