2016-07-05 20:34:52 +02:00
|
|
|
module utility;
|
|
|
|
|
|
|
|
auto concat(T : E[n], E, size_t n)(in E[][] args...) @nogc
|
|
|
|
{
|
|
|
|
size_t offset = 0;
|
|
|
|
T result = void;
|
|
|
|
foreach(arr; args) {
|
|
|
|
result[offset .. offset+arr.length] = arr;
|
|
|
|
offset += arr.length;
|
|
|
|
}
|
|
|
|
assert(offset == result.length);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-07-06 02:00:03 +02:00
|
|
|
@safe unittest
|
|
|
|
{
|
|
|
|
assert(concat!(int[0])() == []);
|
|
|
|
assert(concat!(int[0])([]) == []);
|
|
|
|
assert(concat!(int[0])([], []) == []);
|
|
|
|
assert(concat!(int[1])([1]) == [1]);
|
|
|
|
assert(concat!(int[1])([1], []) == [1]);
|
|
|
|
assert(concat!(int[1])([], [1]) == [1]);
|
|
|
|
assert(concat!(int[2])([1, 2]) == [1, 2]);
|
|
|
|
assert(concat!(int[2])([1], [2]) == [1, 2]);
|
|
|
|
assert(concat!(int[6])([1], [2, 3], [4, 5, 6]) == [1, 2, 3, 4, 5, 6]);
|
|
|
|
assert(concat!(char[12])("Hello", " ", "World!") == "Hello World!");
|
|
|
|
}
|