Recent

Author Topic: Pre-Specialize Generic Functions  (Read 892 times)

MMarie

  • New Member
  • *
  • Posts: 49
  • Right, lets bodge this pisspot
    • Homepage
Pre-Specialize Generic Functions
« on: February 08, 2026, 08:04:53 pm »
I just stumbled upon https://forum.lazarus.freepascal.org/index.php?topic=61648.0

Whilst trying to find out if I could pre-specialize generic functions that I use quite a lot. Im wondering if some kind of specialize-once mechanism for functions/procedures are planned or if anything speaks against such a thing.

I did also see the suggestion to use some little macros, but this doesn't work for me since I'd want the pre-specializations to be accesible from other units. Defining wrappers would be an option, but since the generic function itself is so short (its a function to emulate ternary-operators) I might as well not rely on generics.
i use arch btw

PascalDragon

  • Hero Member
  • *****
  • Posts: 6356
  • Compiler Developer
Re: Pre-Specialize Generic Functions
« Reply #1 on: February 09, 2026, 09:36:02 pm »
Whilst trying to find out if I could pre-specialize generic functions that I use quite a lot. Im wondering if some kind of specialize-once mechanism for functions/procedures are planned or if anything speaks against such a thing.

No, something like that is not planned.

Khrys

  • Sr. Member
  • ****
  • Posts: 402
Re: Pre-Specialize Generic Functions
« Reply #2 on: February 10, 2026, 07:02:30 am »
I think implicit specialization might provide the same ergonomics:

Code: Pascal  [Select][+][-]
  1. {$modeswitch implicitfunctionspecialization}
  2.  
  3. Assert(2026 = IfThen(2 + 2 = 5, 1984, 2026));
  4. Assert('yeah' = IfThen(True, 'yeah', 'nope'));

jamie

  • Hero Member
  • *****
  • Posts: 7610
Re: Pre-Specialize Generic Functions
« Reply #3 on: February 23, 2026, 01:09:51 pm »
OR if they ever release the Trunk which I believe they were or did implement a real ifthen you can do this instead.
Code: Pascal  [Select][+][-]
  1. SomeItem := If someCondition then resultTrue else ResultFalse;
  2.  
  3.  

That generates a real ifthen.

jamie
The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018