Feedback on Átila's Vision for D

jmh530 john.michael.hall at gmail.com
Tue Oct 15 17:50:52 UTC 2019


On Tuesday, 15 October 2019 at 16:39:47 UTC, Paul Backus wrote:
> [snip]
>
> 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) { ... }
>
> .[snip]

That's an interesting point. The problem is the template 
constraints aren't considered for the overloading, right? 
However, if they were expressed as in something like below

auto myAlgorithm(T)(InputRange!T r) { ... }
auto myAlgorithm(T)(RandomAccessRange!T r) { ... }

then I presume that it wouldn't be an issue. You might find DIP 
1023 [1] interesting. One of the purposes of DIP1023 is to allow 
for template aliases to be used like types in functions. One of 
the arguments against DIP1023 is that you can simply use template 
constraints to do the same thing. However, your example shows 
that template constraints might get complicated in some instances.

[1] 
https://github.com/dlang/DIPs/blob/bf5157d3dc29a591826e22d188448fbc04ca81b2/DIPs/DIP1023.md




More information about the Digitalmars-d mailing list