View mode: basic / threaded / horizontal-split · Log in · Help
January 23, 2012
Re: Aliasing of template results
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...
January 24, 2012
Re: Aliasing of template results
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.
January 24, 2012
Re: Aliasing of template results
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
January 25, 2012
Re: Aliasing of template results
On 22 January 2012 20:36, Alex Rønne Petersen <xtzgzorex@gmail.com> wrote:

> 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?


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...
Next ›   Last »
1 2
Top | Discussion index | About this forum | D home