array operations and ranges

Vlad Levenfeld via Digitalmars-d digitalmars-d at puremagic.com
Sun Apr 26 12:58:37 PDT 2015


Manu, I just saw your other post clarifying the code was float[N] 
a = ..., not float[] a. That changes things a bit.

I just implemented a static array type in the lib (1-d only for 
now) which can do the following:

unittest {
	import std.range: only;

	StaticArray!(int, 2) x;

	assert (x[] == [0, 0]);

	x[0..2] = only (5, 6);

	assert (x[] == [5, 6]);

	x[] += 5;

	assert (x[] == [10, 11]);

	x[0..1] -= 5;

	assert (x[] == [5, 11]);

	StaticArray!(int, 4) y = only (1,2,3,4);

	assert (y[] == [1, 2, 3, 4]);

	auto z = only (9,8,7).static_array!([3]);

	assert (z[] == [9, 8, 7]);
}


Assertions are thrown if the assigned range doesn't match the 
static array length.

https://github.com/evenex/autodata/blob/master/source/spaces/array.d


More information about the Digitalmars-d mailing list