Why MapResult.empty() is not const in Phobos?

Timon Gehr timon.gehr at gmx.ch
Sat Jul 6 17:41:52 UTC 2019


On 06.07.19 07:37, valmat wrote:
> Minimal examples when it broke code:
> https://run.dlang.io/is/HbEfkJ
> https://run.dlang.io/is/4h1B6Z
> 

1. Because there is no const inference (yet?).
2. An immutable range makes no sense anyway. Note that trying to do 
C++-style "const-correctness" is not a good idea in D, mostly because of 1.

I.e., the problem is that you are using `const`.

Whatever comes out of this, slapping `const` on `MapResult.empty` is not 
the way to fix this.

Here's an example where a `const` somewhere in Phobos is actively 
breaking code:

import std.stdio, std.typecons;
struct S{
     string toString(){ return "not broken"; }
}
void main(){
     writeln(S()); // "not broken"
     writeln(tuple(S(),S())); // "Tuple!(S, S)(const(S)(), const(S)())" wtf?
}

This is just annoying.


More information about the Digitalmars-d mailing list