diff --git a/lib/std/core/builtin.c3 b/lib/std/core/builtin.c3 index c07cf75f3..378866f79 100644 --- a/lib/std/core/builtin.c3 +++ b/lib/std/core/builtin.c3 @@ -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. * diff --git a/lib/std/list.c3 b/lib/std/list.c3 index 45757fecc..c8901b3b1 100644 --- a/lib/std/list.c3 +++ b/lib/std/list.c3 @@ -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) {