Paste: value semantics test

Author: kssreeram
Mode: text
Date: Thu, 30 Sep 2010 10:25:15
Plain Text |
var _nextId = 0;

nextId() {
    var id = _nextId;
    _nextId += 1;
    return id;
}

record Test (
    id : Int
);

overload RegularRecord?(static Test) = false;

overload Test(id:Int) returned:Test {
    println("construct Test(id) ", id);
    returned.id = id;
}

overload Test() returned:Test {
    var id = nextId();
    println("construct Test ", id);
    returned.id = id;
}

overload Test(src:Test) returned:Test {
    println("copy Test ", src.id);
    returned.id = src.id;
}

overload moveUnsafe(src:Test) returned:Test {
    println("move Test ", src.id);
    returned.id = src.id;
}

overload resetUnsafe(x:Test) {
    var id = nextId();
    println("reset Test ", id);
    x.id = id;
}

overload destroy(x:Test) {
    println("destroy Test ", x.id);
}

overload assign(dest:Test, src:Test) {
    dest.id = src.id;
}

main() {
    var a = Vector(map(Test, range(3)));
}

New Annotation

Summary:
Author:
Mode:
Body: