You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To implement efficient seq-like value semantics, overloading the assignment operator = is needed. However, every use of = will then create a copy even object construction
typeBaz=object
data: intFoobar=object
a: int
data_ref: refBazprocnewFoobar(a: int, data: int): Foobar=result.a = a
newresult.data_ref
result.data_ref[].data = data
proc`=`(dest: varFoobar, src: Foobar) =
dest.a = src.a
new dest.data_ref
dest.data_ref[] = src.data_ref[]
echo"Value copied"let a =newFoobar(10, 50)
echo a.repr
To implement efficient seq-like value semantics, overloading the assignment operator
=
is needed. However, every use of=
will then create a copy even object constructionOutput:
Trying to implement move optimization doesn't work, I get
Error: cannot bind another '=' to: Foobar
with the following code:
The text was updated successfully, but these errors were encountered: