2014-12-30 01:22:09 -05:00
|
|
|
import io:*;
|
|
|
|
|
import mem:*;
|
|
|
|
|
import vector:*;
|
2014-06-30 01:57:50 -07:00
|
|
|
|
2015-05-16 12:05:23 -04:00
|
|
|
obj AbleToBeDestroyed (Destructable) {
|
2015-05-09 06:24:56 -04:00
|
|
|
fun destruct(): void {
|
2014-07-06 23:42:25 -07:00
|
|
|
println("Destroyed!");
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2015-05-09 06:24:56 -04:00
|
|
|
fun main(): int {
|
|
|
|
|
var intVec.construct(): vector<int>;
|
2014-07-23 02:23:21 -07:00
|
|
|
intVec.addEnd(1);
|
|
|
|
|
intVec.addEnd(3);
|
|
|
|
|
intVec.addEnd(3);
|
|
|
|
|
intVec.addEnd(7);
|
2015-03-11 01:58:10 -04:00
|
|
|
println(intVec.size);
|
2015-05-09 06:24:56 -04:00
|
|
|
for (var i: int = 0; i < intVec.size; i++;)
|
2014-06-30 01:57:50 -07:00
|
|
|
print(intVec.at(i));
|
2015-05-27 00:58:33 -04:00
|
|
|
println();
|
|
|
|
|
|
|
|
|
|
// in place lambda map
|
|
|
|
|
intVec.in_place(fun(it:int):int { return it*2; })
|
|
|
|
|
for (var i: int = 0; i < intVec.size; i++;)
|
|
|
|
|
print(intVec.at(i));
|
|
|
|
|
println();
|
|
|
|
|
|
|
|
|
|
var subd = intVec.map(fun(it:int):int { return it-1; })
|
|
|
|
|
for (var i: int = 0; i < subd.size; i++;)
|
|
|
|
|
print(subd.at(i));
|
|
|
|
|
println();
|
2014-12-30 01:22:09 -05:00
|
|
|
|
2015-05-27 00:58:33 -04:00
|
|
|
var newType = intVec.map(fun(it:int):double { return it+1.7; })
|
|
|
|
|
for (var i: int = 0; i < newType.size; i++;)
|
|
|
|
|
print(newType.at(i));
|
2014-06-30 01:57:50 -07:00
|
|
|
println();
|
2014-12-30 01:22:09 -05:00
|
|
|
|
2015-05-09 06:24:56 -04:00
|
|
|
var desVec: vector<AbleToBeDestroyed>* = new<vector<AbleToBeDestroyed>>()->construct();
|
|
|
|
|
var testDestruct: AbleToBeDestroyed;
|
2014-07-23 02:23:21 -07:00
|
|
|
desVec->addEnd(testDestruct);
|
|
|
|
|
delete<vector<AbleToBeDestroyed>>(desVec);
|
2014-07-06 23:42:25 -07:00
|
|
|
|
2014-06-30 01:57:50 -07:00
|
|
|
return 0;
|
|
|
|
|
}
|