namespace; include rt; // methods on generic structs: each set of type arguments gets its own copy struct pt { int x, y; }; struct table { int n; K* keys; V* vals; fn init(int cap) { this.n = 0; this.keys = rt.new(K, cap) as K*; this.vals = rt.new(V, cap) as V*; return 0; } fn put(K k, V v) { this.keys[this.n] = k; this.vals[this.n] = v; this.n++; return this.n; } fn width() { return sizeof(K) * 10 + sizeof(V); } fn total() { int s = 0; for (int i = 0; i < this.n; i++) s += this.vals[i]; return s; } }; int main() { table a; a.init(8); a.put(1, 10); a.put(2, 20); a.put(3, 30); rt.put_n(a.n); rt.put_c(' '); rt.put_n(a.total()); rt.put_c(' '); rt.put_n(a.width()); rt.put_c(' '); table* b = rt.new(table); b.init(4); rt.put_n(b.width()); rt.put_c(' '); table* c = rt.new(table); c.init(4); rt.put_n(c.width()); rt.put_c(10); return 0; }