Help needed to learn typeof(return)

Vinod K Chandran kcvinu82 at
Sat Mar 26 18:25:54 UTC 2022

Hi all,
I am reading `Programming in D` online book. There is a paragraph 
in the chapter `More Templates`.
typeof(return) generates the return type of a function, inside 
that function.
For example, instead of defining the calculate() function above 
as an auto function, we can be more explicit by replacing auto 
with LargerOf!(A, B) in its definition. (Being more explicit 
would have the added benefit of obviating at least some part of 
its function comment.)
And it shows this code.
LargerOf!(A, B) calculate(A, B)(A a, B b) {
     typeof(return) result;    // The type is either A or B
     // ...
     return result;
The author says `LargerOf!(A, B)` is used instead of `auto` 
keyword. How did compiler understands the return type from 
`LargerOf!(A, B)`.

More information about the Digitalmars-d-learn mailing list