__traits(isSame, TemplateOf ...) errors and some Idiomatic D questions

aliak something at something.com
Mon Jan 8 22:59:44 UTC 2018


Hi, trying to write some idiomatic generic D code and I'm a bit 
stuck with using the TemplateOf to check if a range is a 
SortedRange or not. A bit about the code, I'm basically rewriting 
https://dlang.org/library/std/algorithm/setops/set_difference.html but I want to do different things based on if the passed in ranges are sorted or not.

The error I'm getting is this:

onlineapp.d(61): Error: template std.traits.TemplateOf does not 
match any template declaration. And I use it like this:

enum r1Sorted = __traits(isSame, TemplateOf!(R1), SortedRange);

That's happening on line 61 and the weird thing is that I'm using 
TemplateOf exactly (i think) the same way on lines 28 and 29 and 
those do not error.

The code is here: https://run.dlang.io/is/9fowuP

If I substitute the isSame trait with compiles, then it works:

enum r1Sorted = __traits(compiles, TemplateOf!(R1), SortedRange);
pragma(msg, r1Sorted); // prints true

Any help would be appreciated! And on a side note, if anyone can 
point out any things I'm doing wrong when it comes to using D 
optimally/properly then please do.

Cheers! And thanks for any help!

PS:

1) Is there a better way to check if a predicate is unary or 
binary?
2) Is there an idiomatic way to check if a range is sortable or 
is it just "is(typeof(sort(range)))" basically it?




More information about the Digitalmars-d-learn mailing list