Debug help - Programming in D - extending tail slice terminates sharing unexpectedly. Page 69, 70

Steven Schveighoffer schveiguy at gmail.com
Mon Oct 20 22:56:25 UTC 2025


On Monday, 20 October 2025 at 17:56:24 UTC, monkyyy wrote:

> someone swapped the tradeoffs then calling it a bug is 
> misleading
> if you disagree pls fix this bug
> ```d
> import std;
> bool issubset(T)(T[] a,T[] b){
> 	T* c=min(&a[0],&b[0]);
> 	T* d=max(&a[$-1],&b[$-1]);
> 	return &a[0]==c&& &a[$-1]==d;
> }
> unittest{
> 	int[100] foo;
> 	assert(issubset(foo[10..20],foo[15..19]));
> 	assert( ! issubset(foo[50..100],foo[15..30]));
> }
> unittest{
> 	int[] data=[1,2,3];
> 	int[] tail=data[1..$];
> 	assert(issubset(data,tail));
> 	assert(data.capacity>0);
> 	assert(tail.capacity>0);
> 	data.length+=1;
> 	assert(data[$-1]==int.init);
> 	data[$-1]=4;
> 	assert(data[$-1]==4);
> 	assert(issubset(data,tail));
> 	assert(tail.capacity>0);
> 	tail.length+=1;
> 	assert(tail[$-1]==int.init);
> 	assert(issubset(data,tail));
> }
> ```

Hard to understand this code. If you think this is an issue, 
please file at https://github.com/dlang/dmd/issues

Please include explanatory information, and what you expect to 
happen.

-Steve


More information about the Digitalmars-d-learn mailing list