From 1e6c1019b41b25badd954c53b9233e97debb3e13 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Wed, 14 Feb 2018 12:45:41 -0800 Subject: [PATCH 01/13] core.array.StaticArray --- src/core/array.d | 52 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/core/array.d diff --git a/src/core/array.d b/src/core/array.d new file mode 100644 index 0000000000..c319c424a3 --- /dev/null +++ b/src/core/array.d @@ -0,0 +1,52 @@ +module core.array; + +/++ + Returns a static array constructed from `a` ++/ +CommonType!T[T.length] StaticArray(T...)(T a) +{ + return [a]; +} + +unittest +{ + { + auto a = StaticArray(1, 2, 3); + assert(is(typeof(a) == int[3])); + assert(a == [1, 2, 3]); + } + { + auto a = StaticArray(1, 2.0); + assert(is(typeof(a) == double[2])); + assert(a == [1, 2.0]); + } + assert(!__traits(compiles, StaticArray(1, ""))); + assert(is(typeof(StaticArray()) == void[0])); +} + +package: +// copied from std.traits ; TODO: move to core.internal.adapted? +template CommonType(T...) +{ + static if (!T.length) + { + alias CommonType = void; + } + else static if (T.length == 1) + { + static if (is(typeof(T[0]))) + { + alias CommonType = typeof(T[0]); + } + else + { + alias CommonType = T[0]; + } + } + else static if (is(typeof(true ? T[0].init : T[1].init) U)) + { + alias CommonType = CommonType!(U, T[2 .. $]); + } + else + alias CommonType = void; +} From 478eac0f32a769e3d95f5f798c4c92f2f9678195 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Wed, 14 Feb 2018 13:05:41 -0800 Subject: [PATCH 02/13] fixup --- src/core/array.d | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/core/array.d b/src/core/array.d index c319c424a3..ca6f7e79fa 100644 --- a/src/core/array.d +++ b/src/core/array.d @@ -3,7 +3,7 @@ module core.array; /++ Returns a static array constructed from `a` +/ -CommonType!T[T.length] StaticArray(T...)(T a) +CommonType!T[T.length] staticArray(T...)(T a) { return [a]; } @@ -11,17 +11,18 @@ CommonType!T[T.length] StaticArray(T...)(T a) unittest { { - auto a = StaticArray(1, 2, 3); + auto a = staticArray(1, 2, 3); assert(is(typeof(a) == int[3])); assert(a == [1, 2, 3]); } { - auto a = StaticArray(1, 2.0); + auto a = staticArray(1, 2.0); assert(is(typeof(a) == double[2])); assert(a == [1, 2.0]); } - assert(!__traits(compiles, StaticArray(1, ""))); - assert(is(typeof(StaticArray()) == void[0])); + assert(!__traits(compiles, staticArray(1, ""))); + assert(is(typeof(staticArray()) == void[0])); + // NOTE: `int[] temp=staticArray(1,2)` correctly issues a deprecation } package: From e51f8290d2ed477bba147c7806994cf8dfad4316 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Wed, 14 Feb 2018 13:19:19 -0800 Subject: [PATCH 03/13] fixup --- src/core/array.d | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/core/array.d b/src/core/array.d index ca6f7e79fa..a62ca13c1c 100644 --- a/src/core/array.d +++ b/src/core/array.d @@ -1,9 +1,11 @@ module core.array; /++ - Returns a static array constructed from `a` + Returns a static array constructed from `a`. The type of elements can be + specified implicitly (`int[2] a = staticArray(1,2)`) or explicitly + (`float[2] a = staticArray!float(1,2)`). +/ -CommonType!T[T.length] staticArray(T...)(T a) +pragma(inline, true) U[T.length] staticArray(U = CommonType!T, T...)(T a) { return [a]; } @@ -23,6 +25,12 @@ unittest assert(!__traits(compiles, staticArray(1, ""))); assert(is(typeof(staticArray()) == void[0])); // NOTE: `int[] temp=staticArray(1,2)` correctly issues a deprecation + + { + auto a = staticArray!float(1, 2); + assert(is(typeof(a) == float[2])); + assert(a == [1, 2]); + } } package: From 111642b2df6d7c3e723b786c6ba222532d588365 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Wed, 14 Feb 2018 17:25:09 -0800 Subject: [PATCH 04/13] added asStatic --- src/core/array.d | 91 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 89 insertions(+), 2 deletions(-) diff --git a/src/core/array.d b/src/core/array.d index a62ca13c1c..06add1fc30 100644 --- a/src/core/array.d +++ b/src/core/array.d @@ -24,17 +24,65 @@ unittest } assert(!__traits(compiles, staticArray(1, ""))); assert(is(typeof(staticArray()) == void[0])); - // NOTE: `int[] temp=staticArray(1,2)` correctly issues a deprecation { auto a = staticArray!float(1, 2); assert(is(typeof(a) == float[2])); assert(a == [1, 2]); } + + assert(is(typeof(staticArray([1])) == int[][1])); + + // NOTE: correctly issues a deprecation + //int[] a2 = staticArray(1,2); +} + +pragma(inline, true) T[n] asStatic(T, size_t n)(auto ref T[n] arr) @nogc +{ + return arr; +} + +U[n] asStatic(U, T, size_t n)(auto ref T[n] arr) @nogc if (!is(U == T)) +{ + U[n] ret = void; + static foreach (i; 0 .. n) + cast(Unqual!U)(ret[i]) = arr[i]; + return ret; +} + +unittest +{ + { + auto a = [1, 2, 3].asStatic; + assert(is(typeof(a) == int[3])); + assert(a == [1, 2, 3]); + } + + @nogc void checkNogc() + { + auto a = [1, 2, 3].asStatic; + assert(a == [1, 2, 3]); + } + + { + auto a = [1, 2, 3].asStatic!double; + } + + { + auto a = [1, 2, 3].asStatic!int; + } + { + auto a1 = [1, 2, 3].asStatic!(const(int)); + const(int)[3] a2 = [1, 2, 3].asStatic; + auto a3 = [1, 2, 3].asStatic!(const(double)); + } + // NOTE: correctly issues a deprecation + //int[] a2 = [1,2].asStatic; } package: -// copied from std.traits ; TODO: move to core.internal.adapted? +// TODO: move to core.internal.adapted? +// copied from std.traits.CommonType template CommonType(T...) { static if (!T.length) @@ -59,3 +107,42 @@ template CommonType(T...) else alias CommonType = void; } + +// Copied from std.traits.Unqual +template Unqual(T) +{ + version (none) // Error: recursive alias declaration @@@BUG1308@@@ + { + static if (is(T U == const U)) + alias Unqual = Unqual!U; + else static if (is(T U == immutable U)) + alias Unqual = Unqual!U; + else static if (is(T U == inout U)) + alias Unqual = Unqual!U; + else static if (is(T U == shared U)) + alias Unqual = Unqual!U; + else + alias Unqual = T; + } + else // workaround + { + static if (is(T U == immutable U)) + alias Unqual = U; + else static if (is(T U == shared inout const U)) + alias Unqual = U; + else static if (is(T U == shared inout U)) + alias Unqual = U; + else static if (is(T U == shared const U)) + alias Unqual = U; + else static if (is(T U == shared U)) + alias Unqual = U; + else static if (is(T U == inout const U)) + alias Unqual = U; + else static if (is(T U == inout U)) + alias Unqual = U; + else static if (is(T U == const U)) + alias Unqual = U; + else + alias Unqual = T; + } +} From 462779ae6289d7af9f9b76e4f9df664d6e31fe3c Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Wed, 14 Feb 2018 18:00:28 -0800 Subject: [PATCH 05/13] added asStatic!(2.iota) --- src/core/array.d | 47 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/src/core/array.d b/src/core/array.d index 06add1fc30..8fd5039728 100644 --- a/src/core/array.d +++ b/src/core/array.d @@ -1,10 +1,5 @@ module core.array; -/++ - Returns a static array constructed from `a`. The type of elements can be - specified implicitly (`int[2] a = staticArray(1,2)`) or explicitly - (`float[2] a = staticArray!float(1,2)`). -+/ pragma(inline, true) U[T.length] staticArray(U = CommonType!T, T...)(T a) { return [a]; @@ -37,6 +32,14 @@ unittest //int[] a2 = staticArray(1,2); } +/++ + Returns a static array constructed from `arr`. The type of elements can be + specified implicitly (`int[2] a = [1,2].asStatic;`) or explicitly + (`float[2] a = [1,2].asStatic!float`). + + // PRTMEP: staticArray with a range (including an array) seems to be sufficient. + The result is an rvalue, therefore uses like [1, 2, 3].asStatic.find(x) may be inefficient. ++/ pragma(inline, true) T[n] asStatic(T, size_t n)(auto ref T[n] arr) @nogc { return arr; @@ -50,6 +53,25 @@ U[n] asStatic(U, T, size_t n)(auto ref T[n] arr) @nogc if (!is(U == T)) return ret; } +auto asStatic(U = typeof(arr[0]), alias arr)() @nogc +{ + enum n = arr.length; + U[n] ret = void; + static foreach (i; 0 .. n) + cast(Unqual!U)(ret[i]) = arr[i]; + return ret; +} + +auto asStatic(alias arr)() @nogc +{ + enum n = arr.length; + alias U = typeof(arr[0]); + U[n] ret = void; + static foreach (i; 0 .. n) + cast(Unqual!U)(ret[i]) = arr[i]; + return ret; +} + unittest { { @@ -78,6 +100,21 @@ unittest } // NOTE: correctly issues a deprecation //int[] a2 = [1,2].asStatic; + + { + import std.range; + + auto a = asStatic!(double, 2.iota); + assert(is(typeof(a) == double[2])); + assert(a == [0, 1]); + } + { + import std.range; + + auto a = asStatic!(2.iota); + assert(is(typeof(a) == int[2])); + assert(a == [0, 1]); + } } package: From 0c58d168e60afa4d83cec11596ca54a4f90f6446 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Wed, 14 Feb 2018 18:10:50 -0800 Subject: [PATCH 06/13] fixup --- src/core/array.d | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/core/array.d b/src/core/array.d index 8fd5039728..be37e5754d 100644 --- a/src/core/array.d +++ b/src/core/array.d @@ -37,7 +37,6 @@ unittest specified implicitly (`int[2] a = [1,2].asStatic;`) or explicitly (`float[2] a = [1,2].asStatic!float`). - // PRTMEP: staticArray with a range (including an array) seems to be sufficient. The result is an rvalue, therefore uses like [1, 2, 3].asStatic.find(x) may be inefficient. +/ pragma(inline, true) T[n] asStatic(T, size_t n)(auto ref T[n] arr) @nogc @@ -45,7 +44,7 @@ pragma(inline, true) T[n] asStatic(T, size_t n)(auto ref T[n] arr) @nogc return arr; } -U[n] asStatic(U, T, size_t n)(auto ref T[n] arr) @nogc if (!is(U == T)) +U[n] asStatic(U, T, size_t n)(auto ref T[n] arr) @nogc if (!is(U == T) && is(T : U)) { U[n] ret = void; static foreach (i; 0 .. n) @@ -98,23 +97,24 @@ unittest const(int)[3] a2 = [1, 2, 3].asStatic; auto a3 = [1, 2, 3].asStatic!(const(double)); } - // NOTE: correctly issues a deprecation - //int[] a2 = [1,2].asStatic; { import std.range; - auto a = asStatic!(double, 2.iota); + enum a = asStatic!(double, 2.iota); assert(is(typeof(a) == double[2])); assert(a == [0, 1]); } { import std.range; - auto a = asStatic!(2.iota); + enum a = asStatic!(2.iota); assert(is(typeof(a) == int[2])); assert(a == [0, 1]); } + + // NOTE: correctly issues a deprecation + //int[] a2 = [1,2].asStatic; } package: From 4f79a3bf372b6549aca8d0eb2d976287383b0bc8 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Wed, 14 Feb 2018 18:17:06 -0800 Subject: [PATCH 07/13] fixup --- src/core/array.d | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/core/array.d b/src/core/array.d index be37e5754d..36692e1557 100644 --- a/src/core/array.d +++ b/src/core/array.d @@ -1,5 +1,12 @@ module core.array; +/++ + Returns a static array constructed from `a`. The type of elements can be + specified implicitly (`int[2] a = staticArray(1,2);`) or explicitly + (`float[2] a = staticArray!float(1,2)`). + + The result is an rvalue, therefore uses like staticArray(1, 2, 3).find(x) may be inefficient. ++/ pragma(inline, true) U[T.length] staticArray(U = CommonType!T, T...)(T a) { return [a]; @@ -52,6 +59,7 @@ U[n] asStatic(U, T, size_t n)(auto ref T[n] arr) @nogc if (!is(U == T) && is(T : return ret; } +/// ditto auto asStatic(U = typeof(arr[0]), alias arr)() @nogc { enum n = arr.length; @@ -61,6 +69,7 @@ auto asStatic(U = typeof(arr[0]), alias arr)() @nogc return ret; } +/// ditto auto asStatic(alias arr)() @nogc { enum n = arr.length; From 758060029cec41ff0793b6d763867159c30efc8b Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Wed, 14 Feb 2018 18:33:25 -0800 Subject: [PATCH 08/13] fixup --- src/core/array.d | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/core/array.d b/src/core/array.d index 36692e1557..abd13d59ae 100644 --- a/src/core/array.d +++ b/src/core/array.d @@ -1,5 +1,6 @@ module core.array; +@safe nothrow pure: /++ Returns a static array constructed from `a`. The type of elements can be specified implicitly (`int[2] a = staticArray(1,2);`) or explicitly @@ -8,6 +9,7 @@ module core.array; The result is an rvalue, therefore uses like staticArray(1, 2, 3).find(x) may be inefficient. +/ pragma(inline, true) U[T.length] staticArray(U = CommonType!T, T...)(T a) +@nogc { return [a]; } @@ -30,7 +32,7 @@ unittest { auto a = staticArray!float(1, 2); assert(is(typeof(a) == float[2])); - assert(a == [1, 2]); + assert(a == [1,2]); } assert(is(typeof(staticArray([1])) == int[][1])); @@ -46,12 +48,15 @@ unittest The result is an rvalue, therefore uses like [1, 2, 3].asStatic.find(x) may be inefficient. +/ -pragma(inline, true) T[n] asStatic(T, size_t n)(auto ref T[n] arr) @nogc +pragma(inline, true) T[n] asStatic(T, size_t n)(auto ref T[n] arr) +@nogc { return arr; } -U[n] asStatic(U, T, size_t n)(auto ref T[n] arr) @nogc if (!is(U == T) && is(T : U)) +U[n] asStatic(U, T, size_t n)(auto ref T[n] arr) +@nogc +if (!is(U == T) && is(T : U)) { U[n] ret = void; static foreach (i; 0 .. n) @@ -60,7 +65,8 @@ U[n] asStatic(U, T, size_t n)(auto ref T[n] arr) @nogc if (!is(U == T) && is(T : } /// ditto -auto asStatic(U = typeof(arr[0]), alias arr)() @nogc +auto asStatic(U = typeof(arr[0]), alias arr)() +@nogc { enum n = arr.length; U[n] ret = void; @@ -70,7 +76,8 @@ auto asStatic(U = typeof(arr[0]), alias arr)() @nogc } /// ditto -auto asStatic(alias arr)() @nogc +auto asStatic(alias arr)() +@nogc { enum n = arr.length; alias U = typeof(arr[0]); From bcf1ee3edecb4914ab991366716a3ffbf0f9b92d Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Wed, 14 Feb 2018 18:39:52 -0800 Subject: [PATCH 09/13] refactor --- src/core/array.d | 87 ++++---------------------------------- src/core/internal/traits.d | 27 ++++++++++++ 2 files changed, 35 insertions(+), 79 deletions(-) diff --git a/src/core/array.d b/src/core/array.d index abd13d59ae..e2ea6a961a 100644 --- a/src/core/array.d +++ b/src/core/array.d @@ -1,5 +1,7 @@ module core.array; +import core.internal.traits : Unqual, CommonType; + @safe nothrow pure: /++ Returns a static array constructed from `a`. The type of elements can be @@ -8,8 +10,7 @@ module core.array; The result is an rvalue, therefore uses like staticArray(1, 2, 3).find(x) may be inefficient. +/ -pragma(inline, true) U[T.length] staticArray(U = CommonType!T, T...)(T a) -@nogc +pragma(inline, true) U[T.length] staticArray(U = CommonType!T, T...)(T a) @nogc { return [a]; } @@ -32,7 +33,7 @@ unittest { auto a = staticArray!float(1, 2); assert(is(typeof(a) == float[2])); - assert(a == [1,2]); + assert(a == [1, 2]); } assert(is(typeof(staticArray([1])) == int[][1])); @@ -48,15 +49,12 @@ unittest The result is an rvalue, therefore uses like [1, 2, 3].asStatic.find(x) may be inefficient. +/ -pragma(inline, true) T[n] asStatic(T, size_t n)(auto ref T[n] arr) -@nogc +pragma(inline, true) T[n] asStatic(T, size_t n)(auto ref T[n] arr) @nogc { return arr; } -U[n] asStatic(U, T, size_t n)(auto ref T[n] arr) -@nogc -if (!is(U == T) && is(T : U)) +U[n] asStatic(U, T, size_t n)(auto ref T[n] arr) @nogc if (!is(U == T) && is(T : U)) { U[n] ret = void; static foreach (i; 0 .. n) @@ -65,8 +63,7 @@ if (!is(U == T) && is(T : U)) } /// ditto -auto asStatic(U = typeof(arr[0]), alias arr)() -@nogc +auto asStatic(U = typeof(arr[0]), alias arr)() @nogc { enum n = arr.length; U[n] ret = void; @@ -76,8 +73,7 @@ auto asStatic(U = typeof(arr[0]), alias arr)() } /// ditto -auto asStatic(alias arr)() -@nogc +auto asStatic(alias arr)() @nogc { enum n = arr.length; alias U = typeof(arr[0]); @@ -132,70 +128,3 @@ unittest // NOTE: correctly issues a deprecation //int[] a2 = [1,2].asStatic; } - -package: -// TODO: move to core.internal.adapted? -// copied from std.traits.CommonType -template CommonType(T...) -{ - static if (!T.length) - { - alias CommonType = void; - } - else static if (T.length == 1) - { - static if (is(typeof(T[0]))) - { - alias CommonType = typeof(T[0]); - } - else - { - alias CommonType = T[0]; - } - } - else static if (is(typeof(true ? T[0].init : T[1].init) U)) - { - alias CommonType = CommonType!(U, T[2 .. $]); - } - else - alias CommonType = void; -} - -// Copied from std.traits.Unqual -template Unqual(T) -{ - version (none) // Error: recursive alias declaration @@@BUG1308@@@ - { - static if (is(T U == const U)) - alias Unqual = Unqual!U; - else static if (is(T U == immutable U)) - alias Unqual = Unqual!U; - else static if (is(T U == inout U)) - alias Unqual = Unqual!U; - else static if (is(T U == shared U)) - alias Unqual = Unqual!U; - else - alias Unqual = T; - } - else // workaround - { - static if (is(T U == immutable U)) - alias Unqual = U; - else static if (is(T U == shared inout const U)) - alias Unqual = U; - else static if (is(T U == shared inout U)) - alias Unqual = U; - else static if (is(T U == shared const U)) - alias Unqual = U; - else static if (is(T U == shared U)) - alias Unqual = U; - else static if (is(T U == inout const U)) - alias Unqual = U; - else static if (is(T U == inout U)) - alias Unqual = U; - else static if (is(T U == const U)) - alias Unqual = U; - else - alias Unqual = T; - } -} diff --git a/src/core/internal/traits.d b/src/core/internal/traits.d index bff5d25319..43fb875383 100644 --- a/src/core/internal/traits.d +++ b/src/core/internal/traits.d @@ -230,3 +230,30 @@ template staticMap(alias F, T...) staticMap!(F, T[$/2 .. $ ])); } } + +// std.traits.CommonType +template CommonType(T...) +{ + static if (!T.length) + { + alias CommonType = void; + } + else static if (T.length == 1) + { + static if (is(typeof(T[0]))) + { + alias CommonType = typeof(T[0]); + } + else + { + alias CommonType = T[0]; + } + } + else static if (is(typeof(true ? T[0].init : T[1].init) U)) + { + alias CommonType = CommonType!(U, T[2 .. $]); + } + else + alias CommonType = void; +} + From 2e140eafa963c4c58f37c7489a5d006953626027 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Wed, 14 Feb 2018 20:01:43 -0800 Subject: [PATCH 10/13] fixup --- src/core/array.d | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/src/core/array.d b/src/core/array.d index e2ea6a961a..95189ee77e 100644 --- a/src/core/array.d +++ b/src/core/array.d @@ -2,7 +2,10 @@ module core.array; import core.internal.traits : Unqual, CommonType; -@safe nothrow pure: +debug import std.stdio; + +// @nogc: https://issues.dlang.org/show_bug.cgi?id=18439 +nothrow @safe pure: /++ Returns a static array constructed from `a`. The type of elements can be specified implicitly (`int[2] a = staticArray(1,2);`) or explicitly @@ -15,6 +18,17 @@ pragma(inline, true) U[T.length] staticArray(U = CommonType!T, T...)(T a) @nogc return [a]; } +// D20180214T185602: Workaround https://issues.dlang.org/show_bug.cgi?id=16779 (make alias to staticArray once fixed) +pragma(inline, true) U[T.length] staticArrayCast(U = CommonType!T, T...)(T a) @nogc +{ + enum n = T.length; + U[n] ret = void; + static foreach (i; 0 .. n) + cast(Unqual!U)(ret[i]) = cast(U)(a[i]); + return ret; +} + +/// unittest { { @@ -34,6 +48,18 @@ unittest auto a = staticArray!float(1, 2); assert(is(typeof(a) == float[2])); assert(a == [1, 2]); + + } + { + // see D20180214T185602 + // auto a = staticArray!byte(1, 2); + auto a = staticArrayCast!byte(1, 2); + assert(is(typeof(a) == byte[2])); + assert(a == [1, 2]); + } + { + auto a = staticArrayCast!byte(1, 129); + assert(a == [1, -127]); } assert(is(typeof(staticArray([1])) == int[][1])); @@ -54,7 +80,8 @@ pragma(inline, true) T[n] asStatic(T, size_t n)(auto ref T[n] arr) @nogc return arr; } -U[n] asStatic(U, T, size_t n)(auto ref T[n] arr) @nogc if (!is(U == T) && is(T : U)) +//U[n] asStatic(U, T, size_t n)(auto ref T[n] arr) @nogc if (!is(U == T) && is(T : U)) +U[n] asStatic(U, T, size_t n)(auto ref T[n] arr) @nogc if (!is(U == T)) { U[n] ret = void; static foreach (i; 0 .. n) @@ -83,6 +110,7 @@ auto asStatic(alias arr)() @nogc return ret; } +/// unittest { { @@ -103,6 +131,9 @@ unittest { auto a = [1, 2, 3].asStatic!int; + // https://issues.dlang.org/show_bug.cgi?id=16779 + //auto a2 = [1, 2, 3].asStatic!byte; + //auto a3 = [1, 2, 3].asStatic!ubyte; } { auto a1 = [1, 2, 3].asStatic!(const(int)); From 2a3ca260c31980c98888230e1a32bcaad3fbdbb4 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Wed, 14 Feb 2018 20:32:01 -0800 Subject: [PATCH 11/13] fixup --- src/core/array.d | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/core/array.d b/src/core/array.d index 95189ee77e..b702d54923 100644 --- a/src/core/array.d +++ b/src/core/array.d @@ -11,7 +11,8 @@ nothrow @safe pure: specified implicitly (`int[2] a = staticArray(1,2);`) or explicitly (`float[2] a = staticArray!float(1,2)`). - The result is an rvalue, therefore uses like staticArray(1, 2, 3).find(x) may be inefficient. + D20180214T203015: The result is an rvalue, therefore uses like + `foo(staticArray(1, 2, 3)` may be inefficient because of the copies. +/ pragma(inline, true) U[T.length] staticArray(U = CommonType!T, T...)(T a) @nogc { @@ -73,7 +74,7 @@ unittest specified implicitly (`int[2] a = [1,2].asStatic;`) or explicitly (`float[2] a = [1,2].asStatic!float`). - The result is an rvalue, therefore uses like [1, 2, 3].asStatic.find(x) may be inefficient. + See also D20180214T203015. +/ pragma(inline, true) T[n] asStatic(T, size_t n)(auto ref T[n] arr) @nogc { From 69d0176cf706c42e46aee7d8d0181fa4cab64733 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Wed, 14 Feb 2018 20:39:54 -0800 Subject: [PATCH 12/13] fixup --- src/core/array.d | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/core/array.d b/src/core/array.d index b702d54923..c18755e587 100644 --- a/src/core/array.d +++ b/src/core/array.d @@ -6,13 +6,13 @@ debug import std.stdio; // @nogc: https://issues.dlang.org/show_bug.cgi?id=18439 nothrow @safe pure: -/++ - Returns a static array constructed from `a`. The type of elements can be - specified implicitly (`int[2] a = staticArray(1,2);`) or explicitly - (`float[2] a = staticArray!float(1,2)`). - D20180214T203015: The result is an rvalue, therefore uses like - `foo(staticArray(1, 2, 3)` may be inefficient because of the copies. +/++ +Returns a static array constructed from `a`. The type of elements can be +specified implicitly (`int[2] a = staticArray(1,2);`) or explicitly +(`float[2] a = staticArray!float(1,2)`). +D20180214T203015: The result is an rvalue, therefore uses like +`foo(staticArray(1, 2, 3)` may be inefficient because of the copies. +/ pragma(inline, true) U[T.length] staticArray(U = CommonType!T, T...)(T a) @nogc { @@ -70,11 +70,10 @@ unittest } /++ - Returns a static array constructed from `arr`. The type of elements can be - specified implicitly (`int[2] a = [1,2].asStatic;`) or explicitly - (`float[2] a = [1,2].asStatic!float`). - - See also D20180214T203015. +Returns a static array constructed from `arr`. The type of elements can be +specified implicitly (`int[2] a = [1,2].asStatic;`) or explicitly +(`float[2] a = [1,2].asStatic!float`). +See also D20180214T203015. +/ pragma(inline, true) T[n] asStatic(T, size_t n)(auto ref T[n] arr) @nogc { From 588ed37aa56eed63814c4f01515522404cd9d7f5 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Wed, 14 Feb 2018 20:59:51 -0800 Subject: [PATCH 13/13] fixup --- src/core/array.d | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/array.d b/src/core/array.d index c18755e587..71ee76b826 100644 --- a/src/core/array.d +++ b/src/core/array.d @@ -20,7 +20,7 @@ pragma(inline, true) U[T.length] staticArray(U = CommonType!T, T...)(T a) @nogc } // D20180214T185602: Workaround https://issues.dlang.org/show_bug.cgi?id=16779 (make alias to staticArray once fixed) -pragma(inline, true) U[T.length] staticArrayCast(U = CommonType!T, T...)(T a) @nogc +pragma(inline, true) U[T.length] staticArrayCast(U, T...)(T a) @nogc { enum n = T.length; U[n] ret = void; @@ -66,7 +66,7 @@ unittest assert(is(typeof(staticArray([1])) == int[][1])); // NOTE: correctly issues a deprecation - //int[] a2 = staticArray(1,2); + // int[] a2 = staticArray(1,2); } /++