Recent

Author Topic: "generic" for "helper"  (Read 206 times)

beria

  • Jr. Member
  • **
  • Posts: 70
"generic" for "helper"
« on: September 22, 2022, 07:07:32 am »
Code: Pascal  [Select][+][-]
  1.   generic  TDynHelper<T> = record helper for TDyn
  2.      function Get(Index: ptrUInt): T;inline;
  3.  end;
  4. .....
  5. implementation  
  6. ......
  7.  
  8. function  TDynHelper.Get(Index: ptrUInt): T;
  9. begin
  10.   Result := T(It(Index)^);
  11. end;
  12.  
  13.  



It won't compile.
The reasons?
1. It is not possible and will never be possible.
2. It will, but in the future.
3. I am an idiot and my syntax is wrong.
4. Everything is done in a different way...
5.  ?
:-)


KodeZwerg

  • Hero Member
  • *****
  • Posts: 538
  • Fifty shades of code.
    • Delphi & FreePascal
Re: "generic" for "helper"
« Reply #1 on: September 22, 2022, 07:13:53 am »
https://wiki.freepascal.org/Helper_types#Record_Helper
I guess "generic" not (yet) supported.
(and i did not have checked your syntax)
« Last Edit: Tomorrow at 31:76:97 by KodeZwerg »

PascalDragon

  • Hero Member
  • *****
  • Posts: 4756
  • Compiler Developer
Re: "generic" for "helper"
« Reply #2 on: September 22, 2022, 08:52:49 am »
2. It will, but in the future.

It will most likely be this one. At least it's on my ToDo list, but please note that you'll always need to specialize such helpers yourself (e.g. type TLongIntDynHelper = specialize TDynHelper<LongInt>;), the compiler won't auto-magically try to specialize any generic type helper that might be suitable for you.

 

TinyPortal © 2005-2018