Rant after trying Rust a bit

Vlad Levenfeld via Digitalmars-d digitalmars-d at puremagic.com
Thu Jul 23 13:50:55 PDT 2015


On Thursday, 23 July 2015 at 20:40:17 UTC, Walter Bright wrote:
> On 7/23/2015 12:50 PM, H. S. Teoh via Digitalmars-d wrote:
>> That assumes the template author is diligent (foolhardy?) 
>> enough to
>> write unittests that cover all possible instantiations...
>
> No, only each branch of the template code must be instantiated, 
> not every possible instantiation. And we have a tool to help 
> with that: -cov
>
> Does anyone believe it is a good practice to ship template code 
> that has never been instantiated?

I dunno about good practices but I have some use cases.

I write a bunch of zero-parameter template methods and then pass 
them into a Match template which attempts to instantiate each of 
them in turn, settling on the first one which does compile. So 
the methods basically form a list of "preferred implementation of 
functionality X". All but one winds up uninstantiated.

I also use a pattern where I mix in a zero-parameter template 
methods into a struct - they don't necessarily work for that 
struct, but they won't stop compilation unless they are 
instantiated. A complete interface is generated but only the 
subset which the context actually supports can be successfully 
instantiated - and anything the caller doesn't need, doesn't get 
compiled.

Again, not sure if this is a bad or good thing. But I have found 
these patterns useful.


More information about the Digitalmars-d mailing list