Aliasing of template results

Denis Shelomovskij verylonglogin.reg at gmail.com
Sun Jan 22 12:00:01 PST 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?


More information about the Digitalmars-d mailing list