mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Added swap and list swap to stdlib.
This commit is contained in:
@@ -27,6 +27,13 @@ macro void @scope(&variable; @body) @autoimport
|
||||
@body();
|
||||
}
|
||||
|
||||
macro void @swap(&a, &b) @autoimport
|
||||
{
|
||||
$typeof(a) temp = a;
|
||||
a = b;
|
||||
b = temp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a variant type to a type, returning an failure if there is a type mismatch.
|
||||
*
|
||||
|
||||
@@ -115,6 +115,10 @@ fn void List.free(List *list)
|
||||
list.size = 0;
|
||||
}
|
||||
|
||||
fn void List.swap(List *list, usize i, usize j)
|
||||
{
|
||||
@swap(list.entries[i], list.entries[j]);
|
||||
}
|
||||
|
||||
macro Type List.@item_at(List &list, usize index) @operator(elementat)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user