[Issue 6256] [patch] std.algorithm.map does not support static arrays and has 'length' for narrow strings.

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Fri Dec 5 16:06:14 PST 2014


https://issues.dlang.org/show_bug.cgi?id=6256

bearophile_hugs at eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs at eml.cc

--- Comment #4 from bearophile_hugs at eml.cc ---
(In reply to hsteoh from comment #3)
> The length issue has already been fixed.
> 
> As for static arrays, I think the consensus on github is that static arrays
> are not ranges; if you want to use an algorithm on a static array, use [] to
> slice it first (akin to using [] on std.container containers to get a range
> out of them -- containers are not ranges).

Slicing a fixed size array works, but it throws away an extremely useful piece
of information, namely the compile-time knowledge of their length. This is
awful for small arrays, because it kills the simple possibilities of the
compiler to unroll loops and perform other optimizations. You have a language
with a strong type system that keeps the compile-time length of some arrays,
and then you throw it away, this is very bad. Phobos will need to take much
more in account the presence of fixed-size arrays if it wants to be an
efficient library.

What I'd like is to map to call a specialized map function if you call it on a
_small_ fixed-size array, and such map can call the regular map function with
longer fixed-size arrays. This avoids template bloat and helps the back-end
optimize for small loops. I guess it's better to open a new enhancement request
for this?

--


More information about the Digitalmars-d-bugs mailing list