Some bugfixes and added templated member functions\! (even for templated objs\!) In this vein, added in_place and map functions to vector\!
This commit is contained in:
3
tests/test_templateMemberFunction.expected_results
Normal file
3
tests/test_templateMemberFunction.expected_results
Normal file
@@ -0,0 +1,3 @@
|
||||
3.141592
|
||||
7
|
||||
hi
|
||||
30
tests/test_templateMemberFunction.krak
Normal file
30
tests/test_templateMemberFunction.krak
Normal file
@@ -0,0 +1,30 @@
|
||||
import io:*
|
||||
|
||||
obj templd<T> {
|
||||
var data: T
|
||||
fun construct(dataIn:T):void {
|
||||
data = dataIn
|
||||
}
|
||||
fun conv<U>(func: fun(T):U): U {
|
||||
return func(data)
|
||||
}
|
||||
}
|
||||
|
||||
obj onlyMember {
|
||||
var data: int
|
||||
fun printAThing<T>(otherDat: T):void {
|
||||
println(data)
|
||||
println(otherDat)
|
||||
}
|
||||
}
|
||||
|
||||
fun main():int {
|
||||
var hmm.construct(3): templd<int>
|
||||
println(hmm.conv(fun(it:int):double { return it + 0.141592; }))
|
||||
|
||||
var onlyM: onlyMember
|
||||
onlyM.data = 7
|
||||
onlyM.printAThing("hi")
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
4
|
||||
1337
|
||||
26614
|
||||
15513
|
||||
3.7000007.7000007.70000015.700000
|
||||
Destroyed!
|
||||
|
||||
@@ -17,7 +17,22 @@ fun main(): int {
|
||||
println(intVec.size);
|
||||
for (var i: int = 0; i < intVec.size; i++;)
|
||||
print(intVec.at(i));
|
||||
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();
|
||||
|
||||
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));
|
||||
println();
|
||||
|
||||
var desVec: vector<AbleToBeDestroyed>* = new<vector<AbleToBeDestroyed>>()->construct();
|
||||
|
||||
Reference in New Issue
Block a user