https://kotlinlang.org logo
Title
k

karelpeeters

06/05/2019, 5:39 PM
Create a field
cols
with an
operator fun set
and you can do
M.cols[3] = v
.
h

Hullaballoonatic

06/05/2019, 5:43 PM
I have a cols field which returns a list of the column vectors
i've never thought it possible to write operator overload functions for individual fields
that's possible?
I thought a fields set operator had to have a parameter of the precise type as the type of the field's declaration
k

karelpeeters

06/05/2019, 5:46 PM
No you can't, you need an extra class and instance for this.
h

Hullaballoonatic

06/05/2019, 5:47 PM
i figured
so i'd need to create a Rows class and a Cols class, essentially
k

karelpeeters

06/05/2019, 5:47 PM
Yes.
h

Hullaballoonatic

06/05/2019, 5:47 PM
alright, doable
k

karelpeeters

06/05/2019, 5:47 PM
I'm not sure which one the JVM is best at inlining away, a permanent field or a new instance returned every time from the
cols
getter.
Something to benchmark.
h

Hullaballoonatic

06/05/2019, 5:48 PM
yeah, you either have to add stuff to constantly update the permanent field or it's expensive to access it every time
k

karelpeeters

06/05/2019, 5:48 PM
You don't need to update anything.
h

Hullaballoonatic

06/05/2019, 5:48 PM
i can use an inner class
it'll just store pointers basically
k

karelpeeters

06/05/2019, 5:49 PM
Yes.