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

Jonathan M Davis newsgroup.d at jmdavisprog.com
Sat Jul 6 06:56:22 UTC 2019

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

More information about the Digitalmars-d mailing list