Feedback on Átila's Vision for D

Sebastiaan Koppe mail at skoppe.eu
Wed Oct 16 06:53:37 UTC 2019


On Tuesday, 15 October 2019 at 16:39:47 UTC, Paul Backus wrote:
> The one advantage C++ concepts have over D's template 
> predicates is that they're transparent to the compiler. As a 
> result, the compiler is able to determine a partial order on 
> template constraints [1], and use that order to resolve 
> overloads (just like D does with regular function overloads 
> [2]). D can't do this, so we're stuck writing awkward things 
> like this:
>
> auto myAlgorithm(R)(R r) if (isInputRange!R && 
> !isRandomAccessRange!R) { ... }
> auto myAlgorithm(R)(R r) if (isRandomAccessRange!R) { ... }

Surely it would be possible to define a partial ordering over our 
template constraints.

Since isRandomAccessRange!R includes isForwardRange!R (which 
includes isInputRange!R), the compiler should be able to 
determine that isRandomAccessRange!R is more strict than 
isInputRange!R.

If anything, you could simply count the && and the ||'s. That is, 
A && B > B. That ought to be a simple AST+lookup operation. Right?


More information about the Digitalmars-d mailing list