import std.stdio; import std.variant; struct Vec(T, int N) { this (T v) { elements = v; } this (T[] v) { elements = v[0..N]; } @property T[] toArray() { return elements; } alias toArray this; T[N] elements; } void test() { alias vec4f = Vec!(float, 4); assert (vec4f(5).elements[3] == 5); assert (vec4f([5, 6, 7, 3, 5, 8, 56]).elements[] == [5, 6, 7, 3]); //assert (vec4f( vec4f([1, 2, 3, 4]) ).elements[0] == 1); } /* Hello World Program in D Programming */ void main(string[ ] args) { writeln(__LINE__); test(); Vec!(float, 4) v; }
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy. Accept Learn more