Rant after trying Rust a bit

jmh530 via Digitalmars-d digitalmars-d at puremagic.com
Sat Jul 25 19:15:18 PDT 2015


On Sunday, 26 July 2015 at 00:31:48 UTC, Jonathan M Davis wrote:
> On Friday, 24 July 2015 at 01:09:19 UTC, H. S. Teoh wrote:
>
> The second issue that I see with your suggestion is basically 
> what Walter is saying the problem is. Even if we assume that we 
> _do_ want to put all of the requirements for foo - direct or 
> indirect - in its template constraint, this causes a 
> maintenance problem. For instance, if foo were updated to call 
> another function
>

I think from your post I finally understand what Walter was 
getting at.

Not sure if this simplifies things, but what if instead you do 
something like

void foo(T)(T t)
	if (__traits(compiles, bar(t) && __traits(compiles, baz(t)))
{
     ...
     auto b = bar(t);
     ...
     auto c = baz(t);
     ...
}

This only really works in the case where it's obvious that you 
are calling some bar(t). It might not work more generally...

Anyway, in your next example, you have additional layers with 
some more condn!T constraints. If instead you just have more 
__traits(compiles, x) for whatever templates they are calling, 
then checking that bar compiles necessarily also tests whether 
those other functions can compile as well. In this way, you're 
testing all the constraints at lower levels. So I guess you would 
still be checking that each constraint works, but at the highest 
level you only have to specify that the templates you are calling 
compile.

In my opinion this is superior (for this case) because if you 
change bar and baz then you don't have to make changes to foo.

Am I wrong? Is this just another way of doing the same thing?


More information about the Digitalmars-d mailing list