Re: [fpc-pascal] How to inline CompareFunc to Sort method in generic abstract class

2022-12-13 Thread Adrian Veith via fpc-pascal
Hi, with standard generics in pascal there is currently no solution, but you can do it with a "poor man's template". They work with .inc files which contain the generic part of your code and they are then included in your specialization unit. Something like this for a generic sort - I use Del

Re: [fpc-pascal] How to inline CompareFunc to Sort method in generic abstract class

2022-11-21 Thread Flávio Etrusco via fpc-pascal
Em sáb., 19 de nov. de 2022 18:27, Sven Barth via fpc-pascal < fpc-pascal@lists.freepascal.org> escreveu: > (...) > >// this kind of constraint that uses T does not work yet >generic TList> = class > procedure Sort; >end; > > (...) > No? Sad, I use this all the time in Java. Be

Re: [fpc-pascal] How to inline CompareFunc to Sort method in generic abstract class

2022-11-21 Thread Flávio Etrusco via fpc-pascal
; > begin > > Result:=(BRec.A-ARec.A); > > end; > > > > the results are: > > 750ms inlined > > 950ms not inlined, ~21% slower > > 835ms when compare func. is a parameter ~10% slower > > > > so the gain of inlining is higher for sorting primitive types. > V. > > __

Re: [fpc-pascal] How to inline CompareFunc to Sort method in generic abstract class

2022-11-20 Thread Sven Barth via fpc-pascal
Am 20.11.2022 um 02:02 schrieb Hairy Pixels: On Nov 20, 2022, at 4:26 AM, Sven Barth via fpc-pascal wrote: // this kind of constraint that uses T does not work yet generic TList> = class procedure Sort; end; Does this mean the generic param “Comparer” has a constraint which is "s

Re: [fpc-pascal] How to inline CompareFunc to Sort method in generic abstract class

2022-11-19 Thread Hairy Pixels via fpc-pascal
> On Nov 20, 2022, at 4:26 AM, Sven Barth via fpc-pascal > wrote: > > // this kind of constraint that uses T does not work yet > generic TList> = class > procedure Sort; > end; Does this mean the generic param “Comparer” has a constraint which is "specialize TComparer”? I’ve not ever

Re: [fpc-pascal] How to inline CompareFunc to Sort method in generic abstract class

2022-11-19 Thread Sven Barth via fpc-pascal
Am 14.11.2022 um 19:26 schrieb Vojtěch Čihák via fpc-pascal: Hi, I wrote a generic abstract class - a list based on dynamic array (i.e. array of T;) and this class can be specialized elsewhere with any type (records or classes). Part of the class is sorting. There are more ways how to deliver

Re: [fpc-pascal] How to inline CompareFunc to Sort method in generic abstract class

2022-11-19 Thread Sven Barth via fpc-pascal
Am 18.11.2022 um 20:44 schrieb Flávio Etrusco via fpc-pascal: Em seg., 14 de nov. de 2022 15:26, Vojtěch Čihák via fpc-pascal escreveu: Hi, I wrote a generic abstract class - a list based on dynamic array (i.e. array of T;) and this class can be specialized elsewhere with a

Re: [fpc-pascal] How to inline CompareFunc to Sort method in generic abstract class

2022-11-18 Thread Vojtěch Čihák via fpc-pascal
"FPC-Pascal users discussions" Datum: 18.11.2022 20:45 Předmět: Re: [fpc-pascal] How to inline CompareFunc to Sort method in generic abstract class Em seg., 14 de nov. de 2022 15:26, Vojtěch Čihák via fpc-pascal > escreveu:,What do you mean by "be inlined"? The &#

Re: [fpc-pascal] How to inline CompareFunc to Sort method in generic abstract class

2022-11-18 Thread Flávio Etrusco via fpc-pascal
Em seg., 14 de nov. de 2022 15:26, Vojtěch Čihák via fpc-pascal < fpc-pascal@lists.freepascal.org> escreveu: > Hi, > > I wrote a generic abstract class - a list based on dynamic array (i.e. > array of T;) and this class can be specialized elsewhere with any type > (records or classes). > Part of t

Re: [fpc-pascal] How to inline CompareFunc to Sort method in generic abstract class

2022-11-14 Thread Hairy Pixels via fpc-pascal
There’s no way since FPC can’t inline function pointers (I asked already a while ago). It depends on what’s in your list but you can often override comparison operators (like =, < and >) or restructure your classes so there is a base last and then 2+ subclasses that have the top level sorting m

[fpc-pascal] How to inline CompareFunc to Sort method in generic abstract class

2022-11-14 Thread Vojtěch Čihák via fpc-pascal
Hi,   I wrote a generic abstract class - a list based on dynamic array (i.e. array of T;) and this class can be specialized elsewhere with any type (records or classes). Part of the class is sorting. There are more ways how to deliver *compare function* to sorting method. I can pass it as a para