mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Add a concat/tconcat function.
This commit is contained in:
32
lib/std/core/array.c3
Normal file
32
lib/std/core/array.c3
Normal file
@@ -0,0 +1,32 @@
|
||||
module std::core::array;
|
||||
import std::core::mem::array;
|
||||
|
||||
macro tconcat(arr1, arr2)
|
||||
{
|
||||
var $Type = $typeof(arr1[0]);
|
||||
$Type[] result = mem::array::talloc($Type, arr1.len + arr2.len);
|
||||
if (arr1.len > 0)
|
||||
{
|
||||
mem::copy(result.ptr, &arr1[0], arr1.len * $Type.sizeof, $alignof($Type), $alignof($Type));
|
||||
}
|
||||
if (arr2.len > 0)
|
||||
{
|
||||
mem::copy(&result[arr1.len], &arr2[0], arr2.len * $Type.sizeof, $alignof($Type), $alignof($Type));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
macro concat(arr1, arr2)
|
||||
{
|
||||
var $Type = $typeof(arr1[0]);
|
||||
$Type[] result = mem::array::alloc($Type, arr1.len + arr2.len);
|
||||
if (arr1.len > 0)
|
||||
{
|
||||
mem::copy(result.ptr, &arr1[0], arr1.len * $Type.sizeof, $alignof($Type), $alignof($Type));
|
||||
}
|
||||
if (arr2.len > 0)
|
||||
{
|
||||
mem::copy(&result[arr1.len], &arr2[0], arr2.len * $Type.sizeof, $alignof($Type), $alignof($Type));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
Reference in New Issue
Block a user