Added the []= overloadable operator and implemented it for vector, map, and string
This commit is contained in:
@@ -29,6 +29,9 @@ obj map<T,U> {
|
||||
fun find_index(key: T): int {
|
||||
return keys.find_index(key)
|
||||
}
|
||||
fun operator[]=(key: T, value: U) {
|
||||
set(key,value)
|
||||
}
|
||||
fun set(key: T, value: U) {
|
||||
var keyIdx = find_index(key)
|
||||
if (keyIdx >= 0) {
|
||||
|
||||
@@ -43,6 +43,12 @@ obj string (Object) {
|
||||
var new.construct(data.slice(first,second)): string
|
||||
return new
|
||||
}
|
||||
fun operator[]=(index: int, toSet: char) {
|
||||
data[index] = toSet
|
||||
}
|
||||
fun set(index: int, toSet: char) {
|
||||
data.set(index, toSet)
|
||||
}
|
||||
fun length():int { return data.size; }
|
||||
|
||||
fun operator=(str: char*): void {
|
||||
|
||||
@@ -140,6 +140,9 @@ obj vector<T> (Object) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
fun operator[]=(index: int, dataIn: T) {
|
||||
set(index, dataIn)
|
||||
}
|
||||
fun set(index: int, dataIn: T): void {
|
||||
if (index < 0 || index >= size)
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user