Feedback on Átila's Vision for D

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


On Tuesday, 15 October 2019 at 18:39:44 UTC, Paul Backus wrote:
> [snip]
>
> You misunderstand.

I think I understood it, though perhaps I wasn't able to 
communicate myself as well as I tended.

So for instance, suppose we have

enum isSlice(T) = is(T: Slice!(U), U);
auto foo(T)(T m) if(isSlice!T) { /* ... */ }

and then we also add
enum isPackedUpperTriangularMatrix(T) = is(T: 
Slice!(StairsIterator!(U*, "-")), U);
auto foo(T)(T m) if(isPackedUpperTriangularMatrix!T) { /* ... */ }

this has the same problems you describe with input range and 
random access range. A packed upper triangular matrix should 
satisfy both.

DIP1023 addresses creating the alias
alias PackedUpperTriangularMatrix(T) = Slice!(StairsIterator!(T*, 
"-"));
and then enabling the ability to write
auto foo(T)(PackedUpperTriangularMatrix!T m) { }
without the current error.

Nothing would be stopping you from writing the equivalent of
auto foo(T)(Slice!T m) { }
as well.

That last version of foo taking a slice would be the equivalent 
of your input range version, while the second one would be the 
equivalent of random access range version. Unlike above, these 
examples are no longer using the template constraints. It is 
treating the aliases as types so the normal function overloading 
rules should apply.


More information about the Digitalmars-d mailing list