aboutsummaryrefslogtreecommitdiff
path: root/examples/learn/19-growable.zc
blob: 39a484c0b24703277ab506aaefb795cdb12c707f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
namespace;
include rt;
struct cnt {
	int n;
	static int make() { return 3; }
	int get() { return this.n; }
};
fn main() {
	int[?] xs = rt.new(int[?]);
	xs.push(4); xs.push(5);
	rt.put_n(xs.len()); rt.put_c(32); rt.put_n(xs.cap()); rt.put_c(10);
	rt.put_n(xs.pop()); rt.put_c(10);
	xs.resize(4);
	rt.put_n(xs.len()); rt.put_c(10);
	int[3] fixed = {1, 2, 3};
	rt.put_n(fixed.len()); rt.put_c(32); rt.put_n(fixed.cap()); rt.put_c(10);
	rt.put_n(cnt.make()); rt.put_c(10);
}