Why is D unpopular, redux.

Walter Bright newshound2 at digitalmars.com
Tue May 24 23:40:27 UTC 2022


On 5/24/2022 4:21 PM, Timon Gehr wrote:
> For containers: Just consider a struct wrapping a built-in slice.
> 
> struct Slice(T){
>      T[] slice;
> }
> 
> T[] is a subtype of const(T)[], but Slice!T is not a subtype of 
> Slice!(const(T)). In general this cannot be guaranteed, but containers may need 
> to be able to allow this kind of conversions.

What about:

     struct Slice(T) { T[] slice; int* p; }

? A const applied to T will not affect int*, but if the const automatically was 
transferred to Slice, it would, and that would be wrong. It seems you're asking 
for a special case, and as we all lament, special cases lead to corner cases 
with special problems.


> For ranges:
> 
> E.g., here, x is a const slice and can be mapped. The resulting const value 
> cannot be used as a range anymore.
> 
> 
> ```d
> import std.algorithm;
> void main(){
>      const x=[1,2,3,4];
>      const y=x.map!(v=>2*v); // ok
>      const z=y.map!(v=>2*v); // error
> }
> ```
> 
> This kind of thing should just work, but there is no way to strip away the 
> topmost const for a MapResult.

const(int**) p;
cast()(p) produces a const(int*)*

I.e. cast() strips the "head" qualifiers.



>>> There is no way to declare a tail-immutable class reference.
>>>
>>> immutable(int)* <- can rebind the reference, can't assign to value
>>>
>>> immutable(Class) <- can't rebind the reference
>>> Class <- can rebind the reference, can assign to value
>>
>> Should file an Enhancement Request on Bugzilla.
> 
> There's e.g. this one: https://issues.dlang.org/show_bug.cgi?id=5325

thank you


More information about the Digitalmars-d mailing list