Added the []= overloadable operator and implemented it for vector, map, and string

This commit is contained in:
Nathan Braswell
2015-06-27 11:46:31 -04:00
parent b18c18ec30
commit dacfee6d22
13 changed files with 71 additions and 1 deletions

View File

@@ -0,0 +1 @@
bracket assign: index: 4, rhs: 9

View File

@@ -0,0 +1,16 @@
import io:*
obj BracketAssign {
fun operator[]=(index:int, rhs:int) {
print("bracket assign: index: ")
print(index)
print(", rhs: ")
println(rhs)
}
}
fun main():int {
var test:BracketAssign
test[4] = 9
return 0
}

View File

@@ -4,4 +4,5 @@
3
20
2
30
4

View File

@@ -10,9 +10,11 @@ fun main():int {
println(m[3])
m.set(3,4)
m.set(4,20)
m[6] = 30
println(m[1])
println(m[4])
println(m[2])
println(m[6])
println(m[3])
return 0
}

View File

@@ -6,3 +6,4 @@ hope
hope3
new way!
a
now win!

View File

@@ -16,6 +16,10 @@ fun main(): int {
var newWay = string::string("new way!")
io::println(newWay)
io::println(newWay[5])
newWay.set(1, 'o')
newWay[5] = 'i'
newWay[6] = 'n'
io::println(newWay)
return 0;
}

View File

@@ -25,5 +25,10 @@ find test
0
1
2
set and []= test
4
8
9
7
done
Destroyed: 0

View File

@@ -111,6 +111,13 @@ fun main(): int {
println(multipleFindTest.find_index(2))
println(multipleFindTest.find_index(3))
println("set and []= test")
var setTest = vector(4,5,6)
setTest.add(7)
setTest.set(1,8)
setTest[2] = 9
setTest.do(fun(it: int) println(it);)
println("done")
return 0;