<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>Yeah, I noticed that afterwards once I checked. I'm not sure how much sense that actually makes when the TList<T> is a function *result* as it is in the static class function version of Create, though (i.e, you're not assigning an existing TList<T> variable to another, you're returning a brand new one.)</div><div><br></div><div>The version of Copy in my last comment was missing a SetLength, also, and called `Move` incorrectly. Something like this is what I was going for:</div><div><br></div><div>program Test;<br><br>{$mode ObjFPC}<br>{$modeswitch AdvancedRecords}<br><br>type<br> generic TList<T> = record<br> public<br> Data: array of T;<br> class operator Copy(constref Src: TList; var Dest: TList); inline;<br> class function Create(const Num: Integer): TList; static; inline;<br> end;<br> <br> class operator TList.Copy(constref Src: TList; var Dest: TList);<br> var Len: SizeInt;<br> begin<br> Len := Length(Src.Data);<br> SetLength(Dest.Data, Len);<br> Move(Src.Data[0], Dest.Data[0], SizeOf(T) * Len);<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.<br></div><div><br></div><div>Don't forget about your constant generics feature, also... can help in avoiding "constructorish" things altogether quite a bit.</div></div></div>