34 lines
1.3 KiB
Plaintext
34 lines
1.3 KiB
Plaintext
# Only a variadic parameter or a struct's field holds a pack: no union's field,
|
|||
|
|
# local, or binding does, and `...` follows a field's type only where it names
|
||
|
|
# a pack, which takes no default. A field holding a pack is given a pack of its
|
||
|
|
# types. Its values that close are moved out by `...`, or by a literal given
|
||
|
|
# it, so it is then a place that can be written, as is `for const`'s variable
|
||
|
|
# where it writes one.
|
||
|
|
struct bundle<Ts...> { var items: Ts...; }
|
||
|
|
struct noisy : owning { var id: u8; }
|
||
|
|
def noisy::close(&mut this): void {}
|
||
|
|
|
||
|
|
union either<Ts...> { var items: Ts...; var none: u8; }
|
||
|
|
struct plain { var items: u8...; }
|
||
|
|
struct unwritten<Ts...> { var items: Ts; }
|
||
|
|
struct defaulted<Ts...> { var items: Ts... = 0; }
|
||
|
|
|
||
|
|
def take(a: noisy, b: noisy): void {}
|
||
|
|
def bundle<Ts...>::spread_out(&this): void { take(...this.items); }
|
||
|
|
def bundle<Ts...>::walk(&this): void {
|
||
|
|
for const x in this.items { x = x; }
|
||
|
|
}
|
||
|
|
def copied<Ts...>(t: &bundle<Ts...>): bundle<Ts...> { return bundle::<Ts...>{ items = t.items }; }
|
||
|
|
def swapped(a: &bundle<bool, i64>): bundle<i64, bool> { return bundle::<i64, bool>{ items = a.items }; }
|
||
|
|
|
||
|
|
def f<Ts...>(args: Ts...): void {
|
||
|
|
var x: Ts...;
|
||
|
|
val y := args;
|
||
|
|
}
|
||
|
|
def main(): void {
|
||
|
|
var t := bundle::<noisy, noisy>{};
|
||
|
|
val z := t.items;
|
||
|
|
f(1, 2);
|
||
|
|
t.spread_out();
|
||
|
|
_ = copied(&t);
|
||
|
|
}
|