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

Exil Exil at gmall.com
Sat Jul 6 16:18:49 UTC 2019


On Saturday, 6 July 2019 at 06:56:22 UTC, Jonathan M Davis wrote:
> On Friday, July 5, 2019 11:37:10 PM MDT valmat via 
> Digitalmars-d wrote:
>> Minimal examples when it broke code: 
>> https://run.dlang.io/is/HbEfkJ https://run.dlang.io/is/4h1B6Z
>
> In general, it can't be empty, because that would require that 
> the range it's wrapping have a const empty, and most don't. The 
> only way that map (or any wrapper range) can have a const empty 
> would be if it goes to the effort of duplicating the function 
> and uses static ifs to determine whether the version that's 
> const will work or whether the version that's not const needs 
> to be compiled in. And since const ranges are basically 
> unusable, because they can't be iterated, going to that level 
> of effort and making the code messy in that manner is arguably 
> a waste of time.
>
> - Jonathan M Davis

So phobos doesn't properly use const either, officially. Just one 
more reason not to use const on the pile.


More information about the Digitalmars-d mailing list