With regards to this thread
https://forum.lazarus.freepascal.org/index.php/topic,55397.msg412100.html#msg412100,
I was thinking about the "explicit specialization" known from some other programming language.
I've made a very naïve try:
generic function f<_T>: Integer;
begin
result := 0;
end;
generic function f<char>: Integer;
begin
result := 1;
end;
generic function g<_T>: Integer;
begin
result := specialize f<_T>;
end;
begin
writeln(specialize g<char>);
writeln(specialize g<integer>);
end.
Which resulted in several compiler errors:
Compile Project, Target: D:\devel\fpcupdeluxe\projects\project1.exe: Exit code 1, Errors: 6, Hints: 1
project1.lpr(3,20) Hint: Local type "_T" is not used
project1.lpr(8,18) Error: overloaded functions have the same parameter list
project1.lpr(3,18) Error: Found declaration: f$1:LongInt;
project1.lpr(8,18) Error: overloaded functions have the same parameter list
project1.lpr(3,18) Error: Found declaration: f$1$crcE0B4E8C7:LongInt;
project1.lpr(8,18) Error: Function is already declared Public/Forward "f$1$crc3F4CC25F:LongInt;"
project1.lpr(15,13) Error: Compilation raised exception internally
Is that kind of explicit specialization possible in FPC? Maybe I'm using a wrong syntax. Or the problem is in the name mangling scheme?