On Wednesday, 11 December 2013 at 00:37:24 UTC, Namespace wrote:
On Tuesday, 10 December 2013 at 14:20:51 UTC, bearophile wrote:
Namespace:

What's with {1, 2, 3}? Should be easy to implement and it's known from C/C++/Java/C#

In D {} has plenty of meanings already :-)

Bye,
bearophile

You was right, it was terrible and so I tried [1, 2, 3]s as syntax.
It has cost me hours but now this works pretty well:

----
import std.stdio;

void foo(int[3] arr) {
        assert(is(typeof(arr) == int[3]));
}

void bar(T)(T arr) {
        assert(is(T == int[3]));
}

void main() {
        int[] arr0 = [1, 2, 3];
        assert(is(typeof(arr0) == int[]));
        assert(arr0 == [1, 2, 3]);

        int[3] arr1 = [4, 5, 6]s;
        assert(is(typeof(arr1) == int[3]));
        assert(arr1 == [4, 5, 6]);

        int[] arr2 = [7, 8, 9]s;
        assert(is(typeof(arr2) == int[3]));
        assert(arr2 == [7, 8, 9]);

        foo([1, 2, 3]);
        foo([4, 5, 6]s);

        bar([44, 55, 66]s);

        auto arr3 = [111, 222, 333];
        assert(is(typeof(arr3) == int[]));

        auto arr4 = [444, 555, 666]s;
        assert(is(typeof(arr4) == int[3]));
}
----

Would be nice if someone could review it, maybe it's worth to add:

Branch: https://github.com/Dgame/dmd/tree/static_array_literals
Commit: https://github.com/Dgame/dmd/commit/6296057d919d50b407d4533bab5d2a21fba6230c

Reply via email to