www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Can not understand this code.

reply lili <akozhao tencent.com> writes:
Hi:
What is the alias Min = xxx mean? why need defined a alias Min in 
Min template?
```
template Min(alias pred, Args...)
if (Args.length > 0 && __traits(isTemplate, pred))
{
     static if (Args.length == 1)
     {
         alias Min = Alias!(Args[0]);
     }
     else static if (isLess!(pred, Args[1], Args[0]))
     {
         alias Min = Min!(pred, Args[1], Args[2 .. $]);
     }
     else
     {
         alias Min = Min!(pred, Args[0], Args[2 .. $]);
     }
}

```
Oct 24 2019
next sibling parent berni44 <dlang d-ecke.de> writes:
On Friday, 25 October 2019 at 06:40:19 UTC, lili wrote:
 Hi:
 What is the alias Min = xxx mean? why need defined a alias Min 
 in Min template?
 ```
 template Min(alias pred, Args...)
 if (Args.length > 0 && __traits(isTemplate, pred))
 {
     static if (Args.length == 1)
     {
         alias Min = Alias!(Args[0]);
     }
     else static if (isLess!(pred, Args[1], Args[0]))
     {
         alias Min = Min!(pred, Args[1], Args[2 .. $]);
     }
     else
     {
         alias Min = Min!(pred, Args[0], Args[2 .. $]);
     }
 }

 ```
I can't explain in detail, but I know, this is called an eponymous template. See https://dlang.org/spec/template.html#implicit_template_properties
Oct 25 2019
prev sibling parent kinke <kinke gmx.net> writes:
On Friday, 25 October 2019 at 06:40:19 UTC, lili wrote:
 why need defined a alias Min in Min template?
https://dlang.org/spec/template.html#implicit_template_properties
Oct 25 2019