On Thursday, 20 October 2016 at 16:25:53 UTC, Meta wrote:
On Thursday, 20 October 2016 at 13:05:05 UTC, Nordlöw wrote:
On Thursday, 20 October 2016 at 12:38:40 UTC, Nordlöw wrote:
ElementType!R[n] arrayN(size_t n, R)(R r)
{
assert(r.length == n);
typeof(return) dst;
import std.algorithm.mutation : copy;
r.copy(dst[]);
return dst;
}
Is there a place for part of this logic in Phobos?
I'm thinking perhaps array{N,Exactly} should be added to
std.array.
The idea came to me after learning about dependent types in
Idris:
http://www.idris-lang.org/
There was a pull request awhile back for a small function that
creates fixed-length arrays, but I think it was only intended
to create them from dynamic arrays (such as `auto sarr = [1, 2,
3].staticArray`). Personally I think it would be nice to have a
version of `array` that creates a static array, but I don't
know how often it would be used or what the pitfalls are, if
any.
I think you're talking about this PR:
https://github.com/dlang/phobos/pull/4090. It handles range
iteration, as well as opApply iteration.
I also think that the addition is worth having, though Andrei
seemed to disagree. The (other?) major obstacle is safe usage,
which currently is not enforced by the compiler, see:
https://issues.dlang.org/show_bug.cgi?id=8838
https://issues.dlang.org/show_bug.cgi?id=12625
On the bright side, it looks like one of Walter's PRs for DIP1000
should address those issues:
https://github.com/dlang/dmd/pull/5972/files?diff=unified#diff-33b3e2fefc5298c0b9de67897929e7ceR89