Recent

Author Topic: Explicit specialization  (Read 2781 times)

alpine

  • Hero Member
  • *****
  • Posts: 1032
Explicit specialization
« on: July 17, 2021, 10:11:44 am »
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  [Select][+][-]
  1. generic function f<_T>: Integer;
  2. begin
  3.   result := 0;
  4. end;
  5.  
  6. generic function f<char>: Integer;
  7. begin
  8.   result := 1;
  9. end;
  10.  
  11. generic function g<_T>: Integer;
  12. begin
  13.   result := specialize f<_T>;
  14. end;
  15.  
  16. begin
  17.   writeln(specialize g<char>);
  18.   writeln(specialize g<integer>);
  19. end.
Which resulted in several compiler errors:
Code: [Select]
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?
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

jamie

  • Hero Member
  • *****
  • Posts: 6077
Re: Explicit specialization
« Reply #1 on: July 17, 2021, 12:38:50 pm »
doesn't {$MODE Delphi} handle that?
The only true wisdom is knowing you know nothing

alpine

  • Hero Member
  • *****
  • Posts: 1032
Re: Explicit specialization
« Reply #2 on: July 17, 2021, 01:12:31 pm »
doesn't {$MODE Delphi} handle that?

Entirely the same errors with:
Code: Pascal  [Select][+][-]
  1. {$MODE DELPHI}
  2.  
  3. function f<_T>: Integer;
  4. begin
  5.   result := 0;
  6. end;
  7.  
  8. function f<char>: Integer;
  9. begin
  10.   result := 0;
  11. end;
  12.  
  13. function g<_T>: Integer;
  14. begin
  15.   result := f<_T>;
  16. end;

"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

PascalDragon

  • Hero Member
  • *****
  • Posts: 5444
  • Compiler Developer
Re: Explicit specialization
« Reply #3 on: July 17, 2021, 04:05:55 pm »
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?

No, that is not supported.

alpine

  • Hero Member
  • *****
  • Posts: 1032
Re: Explicit specialization
« Reply #4 on: July 17, 2021, 04:32:28 pm »
No, that is not supported.
As terse as it possible.  8-)
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

 

TinyPortal © 2005-2018