[fpc-pascal] Constants in generics
ryan at thealchemistguild.com
Thu Nov 29 03:34:44 CET 2018
> On Nov 28, 2018, at 11:25 PM, Sven Barth via fpc-pascal <fpc-pascal at lists.freepascal.org> wrote:
> You're not wrong, but a type alias is definitely the wrong way.
> But that is a completely different topic, one that I'm not willing to discuss right now, aside from "we don't support something like that”.
Ok, maybe something to think about later. Compile time performance could be a reason to pursue down the road.
> If all that’s involved is comparing params types to generic types then that looks like a relatively simple solution. Const generic params may have complicated this some however.
> Yes, all generic parameters need to be part of the routine's parameters and constant parameters indeed won't work in that case.
What are the performance implications of specializing all these types across a code base? I’ve heard c++ developers mention the terrible performance of templates and I think that’s because of the inferred types and inability to specialize once (like FPC does for all other generics except procs).
Looking at this now I think that each unit that uses an inferred specialization will produce a unit procedure for just that unit. Is that right?
Here’s an example which specializes 3 generics (they’re shared right?) across 5 procedure calls.
generic procedure DoThis<T>(msg:T);
generic procedure DoThis<T>(msg:T;param1:T);
generic procedure DoThis<T>(msg:T;param1:integer);
DoThis('hello'); // specialize DoThis<string>('hello');
DoThis(1); // specialize DoThis<integer>(1);
DoThis('a','b'); // specialize DoThis<string>('a','b’);
DoThis(1,1); // specialize DoThis<integer>(1,1);
DoThis('hello',1); // specialize DoThis<string>(‘hello',1);
More information about the fpc-pascal