Support inline classes working with collection elements (get/set)

This commit is contained in:
Mikhail Zarechenskiy
2018-02-07 15:39:21 +03:00
parent 8015295059
commit 059f1e9eed
9 changed files with 104 additions and 6 deletions

View File

@@ -0,0 +1,23 @@
// !LANGUAGE: +InlineClasses
inline class UInt(private val value: Int) {
fun asInt() = value
}
inline class UIntArray(private val intArray: IntArray) {
operator fun get(index: Int): UInt = UInt(intArray[index])
operator fun set(index: Int, value: UInt) {
intArray[index] = value.asInt()
}
}
fun UIntArray.swap(i: Int, j: Int) {
this[j] = this[i].also { this[i] = this[j] }
}
// 2 INVOKEVIRTUAL UInt.unbox
// 1 INVOKESTATIC UInt\$Erased.box
// 0 intValue
// 0 valueOf