<div dir="ltr"><div dir="ltr">On Mon, Jun 17, 2019 at 5:57 PM Ryan Joseph <<a href="mailto:genericptr@gmail.com">genericptr@gmail.com</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
The copy operator is always called on all assignments. Try actually running that and you’ll see. :)<br></blockquote><div><br></div><div>Actually, after thinking about it some more, here's what I'd actually write (in a perfect world where it was possible.)</div><div><br></div><div>program Test;<br><br>{$mode ObjFPC}<br>{$modeswitch AdvancedRecords}<span class="gmail-im" style="color:rgb(80,0,80)"><br><br>type<br> generic TList<T> = record<br></span> public<br> Data: array of T;</div><div> procedure Assign(var Src: TList); inline;<br> class operator Copy(constref Src: TList; var Dest: TList); // apparently you cannot actually inline this...<br> class function Create(const Num: Integer): TList; static; inline;</div><div> end;</div><div><br></div><div> procedure TList.Assign(var Src: TList);</div><div> var Len: SizeInt;</div><div> begin</div><div> Len := Length(Src.Data);</div> SetLength(Data, Len);<br> Move(Src.Data[0], Data[0], SizeOf(T) * Len);<div> end;<br> <br> class operator TList.Copy(constref Src: TList; var Dest: TList);<br> begin<br> // StaticAssert does not exist, unfortunately...</div><div> StaticAssert(False, 'Don't use the := operator, call Assign instead!');<br> end;<br> <br> class function TList.Create(const Num: Integer): TList; <br> begin<br> SetLength(Result.Data, Num);<br> end;<br><br>begin<br> // Do whatever here.<br>end.</div></div></div>