#line 1 "-" #line 1 "test/copy.g" use "sequence_queries.g"; use "sequence_mutation.g"; use "slist.g"; use "basic_models.g"; use "iterator_models.g"; struct foo { int x; }; /* Need to generate these automaticall! */ model DefaultConstructible { fun new_on_stack() -> foo*@ { return nullptr; } fun new_on_heap() -> foo**@ { return new foo*(); } fun new_on_gc() -> foo**@ { return new GC foo*(); } fun new_placement(void* p) -> foo**@ { return new (p) foo*(); } fun new_array_on_heap(int n) -> foo**@ { return new foo*[n]; } fun new_array_on_gc(int n) -> foo**@ { return new GC foo*[n]; } }; model Regular { fun operator= *(foo*! x ,foo* y) -> foo*! { return x = y; } fun new_on_stack(foo* x) -> foo*@ { return x; } fun new_on_heap(foo* x) -> foo**@ { return new foo*(x); } fun new_on_gc(foo* x) -> foo**@ { return new GC foo*(x); } fun new_placement(void* p, foo* x) -> foo**@ { return new (p) foo*(x); } fun cleanup(foo** x) { delete x; } fun wipeout(foo**) { } }; fun main() -> int@ { /* Copy with input iterators */ { let l = @slist(); let i = 0; while (i != 3) { push_front(2 - i, l); ++i; } let a = new int[3]; copy(begin(l), end(l), a); if (not equal(begin(l), end(l), a)) return 1; } /* Copy with random access iterators */ { let l = new foo[3]; let i = 0; while (i != 3) { l[i] = @foo{x=i}; ++i; } let a = new foo[3]; copy(l, l + 3, a); if (not equal(l, l + 3, a, fun(foo f, foo g): f.x == g.x)) return 2; } /* Copy with pointers and POD type */ { let l = new int[3]; let i = 0; while (i != 3) { l[i] = i; ++i; } let a = new int[3]; copy(l, l + 3, a); if (not equal(l, l + 3, a)) return 3; } return 0; }