Thread overview | ||||||||
---|---|---|---|---|---|---|---|---|
|
January 14, 2015 [Issue 13981] std.algorithm: inconsistent handling of static arrays | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=13981 --- Comment #1 from markus@oberhumer.com --- As metaprogramming in D is so much fun (esp. when coming from C++), I've hacked together some experimental code. Remember that I'm a D newcomer, so please be gentle :-) // dmd 2.066.1 import std.algorithm, std.traits; private auto _rangeForStaticArray(R)(const ref R r) if (isStaticArray!R) { // pseudo code - no idea if it is possible to express hasHeapStorage!R or hasStackStorage!R // - could also test for immutable, but no sure if that's the correct semantics ? // - could also test for something like isGC!R ??? static if (1 || hasHeapStorage!R) { return r[]; // safe } else static if (hasStackStorage!R) { static assert(false, "stack storage for static array not allowed - pass a slice"); return r[]; // possibly unsafe ??? } else { static assert(false, "unknown storage for static array - pass a slice"); } } auto sum(R)(const ref R r) if (isStaticArray!R) { return std.algorithm.sum(_rangeForStaticArray(r)); } auto sum(R)(R r) if (!isStaticArray!R) { return std.algorithm.sum(r); } void test_dynamic_array() { int[] arr1 = [1, 2, 3, 4, 5]; immutable int[] arr2 = [1, 2, 3, 4, 5]; sum(arr1); // OK sum(arr2); // OK } void test_static_array() { int[5] arr1 = [1, 2, 3, 4, 5]; immutable int[5] arr2 = [1, 2, 3, 4, 5]; sum(arr1); // seems OK sum(arr2); // seems OK } -- |
January 15, 2015 [Issue 13981] std.algorithm: inconsistent handling of static arrays | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=13981 Jonathan M Davis <issues.dlang@jmdavisProg.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |issues.dlang@jmdavisProg.co | |m --- Comment #2 from Jonathan M Davis <issues.dlang@jmdavisProg.com> --- In general, I think that it's a big mistake for anything in std.algorinthm or any other range-based functions to support static arrays. If you want to pass a static array to a range-based functions, then you slice it, and you get a dynamic array, which _is_ a valid range. So, we either need to look at removing support for static arrays for any functions in std.algorithm which support them, or we need to explicitly document the cases where they are supported. -- |
October 22, 2015 [Issue 13981] std.algorithm: inconsistent handling of static arrays | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=13981 Jack Stouffer <jack@jackstouffer.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jack@jackstouffer.com --- Comment #3 from Jack Stouffer <jack@jackstouffer.com> --- (In reply to Jonathan M Davis from comment #2) > So, we either need to look at removing support for static arrays for any functions in std.algorithm which support them, or we need to explicitly document the cases where they are supported. Removing support, even though it breaks something, would probably be the best option here. Supporting static arrays in any form in range based code is just confusing. -- |
October 22, 2015 [Issue 13981] std.algorithm: inconsistent handling of static arrays | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=13981 bearophile_hugs@eml.cc changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |bearophile_hugs@eml.cc --- Comment #4 from bearophile_hugs@eml.cc --- The compile-time knowledge of the length of an array is a very precious information, throwing this information away is foolish, especially when the array is short: int[3] a = [1, 10, 30]; immutable total = a.sum; -- |
December 17, 2022 [Issue 13981] std.algorithm: inconsistent handling of static arrays | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=13981 Iain Buclaw <ibuclaw@gdcproject.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Priority|P1 |P4 -- |
December 01 [Issue 13981] std.algorithm: inconsistent handling of static arrays | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=13981 --- Comment #5 from dlangBugzillaToGithub <robert.schadek@posteo.de> --- THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/phobos/issues/10111 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB -- |
Copyright © 1999-2021 by the D Language Foundation