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
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
;
> 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.
>
> __
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
> 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
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
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
"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
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
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
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
11 matches
Mail list logo