www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - 'typeof' not printing template arguments.

reply Deech <aditya.siram gmail.com> writes:
Hi all,
I've been learning D for a few weeks by reading through 
Programming In D [1] and had a question about Eponymous Template 
section [2]. Here's the example:

```
template LargerOf(A, B) {
   static if (A.sizeof < B.sizeof) {
     alias LargerOf = B;

   } else {
     alias LargerOf = A;
   }
}

LargerOf!(A, B) calculate(A, B)(A a, B b) {
   LargerOf!(A, B) result;
   return result;
}

pragma(msg, typeof(calculate));
```

At build time instead of printing:
```
LargerOf!(A, B)(A, B)(A a, B b)
```

it prints:
```
double(double lhs, double rhs)
```

Is there some reason it specializes to `double`?

-deech
[1] http://ddili.org/ders/d.en/index.html
[2] http://ddili.org/ders/d.en/templates_more.html
Jul 11
parent Deech <aditya.siram gmail.com> writes:
On Wednesday, 12 July 2017 at 00:44:38 UTC, Deech wrote:
 Hi all,
 I've been learning D for a few weeks by reading through 
 Programming In D [1] and had a question about Eponymous 
 Template section [2]. Here's the example:

 ```
 template LargerOf(A, B) {
   static if (A.sizeof < B.sizeof) {
     alias LargerOf = B;

   } else {
     alias LargerOf = A;
   }
 }

 LargerOf!(A, B) calculate(A, B)(A a, B b) {
   LargerOf!(A, B) result;
   return result;
 }

 pragma(msg, typeof(calculate));
 ```

 At build time instead of printing:
 ```
 LargerOf!(A, B)(A, B)(A a, B b)
 ```

 it prints:
 ```
 double(double lhs, double rhs)
 ```

 Is there some reason it specializes to `double`?

 -deech
 [1] http://ddili.org/ders/d.en/index.html
 [2] http://ddili.org/ders/d.en/templates_more.html
nm, dumb mistake on my part. I had a `calculate` at the top of the file and missed it. Sorry.
Jul 11