Isn't `each` too much of a good thing?

Avrina avrina12309412342 at
Thu Sep 17 17:56:09 UTC 2020

On Thursday, 17 September 2020 at 16:18:18 UTC, Andrei 
Alexandrescu wrote:
> For example: static arrays are supported. Why? This creates a 
> dangerous precedent whereby we'd need to support static arrays 
> with other primitives, such as map or reduce. (We don't, and we 
> shouldn't. Let them add a "[]" to the array.) Where do you stop?

It should support foreach(), which would support static arrays. 
The problem is there is so many ways to do something, and part of 
that is on Phobos the way ranges were defined and are used. They 
aren't very efficient, they create excessive copies, and if you 
have a type that can't be copied then you pretty much can't use 
it at all.

You have situations like writeln() that uses ranges and doesn't 
have a path for types that support foreach(), this ends up with 
bugs where writeln ends up modifying the const object it was 
passed. Because it has to cast away the constness to be able to 
iterate through a range.

If you only support phobos ranges your are going to be left with 
a gaping hole that's currently filled with a language feature 
(that should be supported).

`reduce` does support static arrays btw.

More information about the Digitalmars-d mailing list