Forum > General

Explicit specialization

(1/1)

alpine:
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:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---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:

--- Code: ---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
--- End code ---

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?

jamie:
doesn't {$MODE Delphi} handle that?

alpine:

--- Quote from: jamie on July 17, 2021, 12:38:50 pm ---doesn't {$MODE Delphi} handle that?

--- End quote ---

Entirely the same errors with:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---{$MODE DELPHI} function f<_T>: Integer;begin  result := 0;end; function f<char>: Integer;begin  result := 0;end; function g<_T>: Integer;begin  result := f<_T>;end;

PascalDragon:

--- Quote from: y.ivanov on July 17, 2021, 10:11:44 am ---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?

--- End quote ---

No, that is not supported.

alpine:

--- Quote from: PascalDragon on July 17, 2021, 04:05:55 pm ---No, that is not supported.

--- End quote ---
As terse as it possible.  8-)

Navigation

[0] Message Index

Go to full version