[fpc-pascal] Generics vs templates
ryan at thealchemistguild.com
Mon Jan 8 12:21:20 CET 2018
> On Jan 8, 2018, at 5:58 PM, Sven Barth via fpc-pascal <fpc-pascal at lists.freepascal.org> wrote:
> FPC essentially reparses a generic during specialization so I'd say that they definitely affect compile times.
Does c++ not “specialize” in one location like FPC? looking at c++ code I often see things like Vector<x> used in multiple locations instead of declaring a single type (I have no idea why they would do that but it’s very common). Maybe that’s why compile times are so slow?
In one instance I did something similar but hopefully it “unfolds” only once when the unit compiles. Is that true?
generic TStaticArray<T> = class (TObject)
generic TDynamicArray<T> = class (specialize TStaticArray<T>)
generic TGenericArray<T> = class (specialize TDynamicArray<T>)
TIntegerArray = specialize TGenericArray<Integer>;
TLongIntArray = specialize TGenericArray<LongInt>;
TStringArray = specialize TGenericArray<String>;
TSingleArray = specialize TGenericArray<Single>;
TDoubleArray = specialize TGenericArray<Double>;
TFloatArray = specialize TGenericArray<TFloat>;
TPointerArray = specialize TGenericArray<Pointer>;
More information about the fpc-pascal