Thread overview |
---|
October 25, 2019 Can not understand this code. | ||||
---|---|---|---|---|
| ||||
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 .. $]); } } ``` |
October 25, 2019 Re: Can not understand this code. | ||||
---|---|---|---|---|
| ||||
Posted in reply to lili | 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 |
October 25, 2019 Re: Can not understand this code. | ||||
---|---|---|---|---|
| ||||
Posted in reply to lili | 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 |
Copyright © 1999-2021 by the D Language Foundation