How templates might be improved

Chris Wright via Digitalmars-d digitalmars-d at puremagic.com
Sat Sep 17 07:29:15 PDT 2016


On Sat, 17 Sep 2016 12:02:47 +0000, Stefan Koch wrote:

> On Friday, 16 September 2016 at 23:44:42 UTC, Chris Wright wrote:
> 
> 
>> On the other hand, in a change of behavior, this will be a cache miss
>> and the template is instantiated twice:
>>
>>   alias myint = int;
>>   alias TypeA = Typedef!int;
>>   alias TypeB = Typedef!myint;
> No It would not be a miss the type is the same

Can you give examples that would produce a cache miss?

>> If someone tries implementing the recursive form of the Fibonacci
>> function with your change in place, they'll have unusably long compile
>> times. However, in the typical case,
>> compile times will be faster (and specific types can more easily
>> receive special treatment as needed).
> 
> If someone tries to implement fibobacci as a recursive template ...
> well there is no way that can be fast.
> With interning or without.

If the compiler caches template instantiations, you get the memoized form 
and it can be computed in linear time. If it doesn't, exponential time.


More information about the Digitalmars-d mailing list