static map as a type function

Bruce Carneal bcarneal at gmail.com
Thu Sep 24 03:37:37 UTC 2020


On Thursday, 24 September 2020 at 02:42:00 UTC, Paul Backus wrote:
> On Thursday, 24 September 2020 at 02:09:31 UTC, Jackel wrote:
>>
>> It's basically what D is to C++ template metaprogramming.
>>
>> Compare the staticMap implementation with a type function 
>> implementation and it's pretty clear which one is more 
>> readable and easier to maintain. The current D implementation 
>> will also create a bunch of template bloat with numerous 
>> instantiations that aren't actually required.
>>
>> StaticMap, and many other templates like it also need a 
>> workaround to reduce the number of instances, otherwise they 
>> fail. Which isn't as intuitive and not something someone will 
>> really know to do.
>
> On the other hand, if you can fix recursive template bloat 
> somehow (tail-call elimination?), you get good performance 
> *and* nice code. It's the best of both worlds.

It would be a very welcome performance improvement for current 
template programming, yes but, for me, type functions are about a 
lot more than the compile time performance improvement they would 
bring.  Making a big chunk of meta programming easier to 
understand, easier to debug, easier to compose, is the big 
payoff.  "It's just like your other programming".

And yes, it would be nice if we could get the performance 
associated with iterative implementations guaranteed rather than 
hope the compiler can find actual recursion within the 
unrestricted polymorphic context of templates.



More information about the Digitalmars-d mailing list