Forum > Free Pascal

Feature announcement: Implicit generic function specializations

<< < (3/4) > >>

Warfley:
Some thing I've found, which I did not report as a bug yet, because I don't know if it is desired (as this might very well introduce a load of unwanted side effects), is that implicit specialization is not recognizing possible implicit casts:

--- 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";}};} ---program Project1; {$mode objfpc}{$H+}{$ModeSwitch advancedrecords}{$ModeSwitch implicitfunctionspecialization} type  generic TTest<T> = record    class operator :=(const rhs: T): specialize TTest<T>;  end; generic procedure Foo<T>(arg: specialize TTest<T>);beginend; begin  specialize foo<Integer>(42); // Works  foo(42); // Errorend.But it could be useful with for example the TNullable type

PascalDragon:

--- Quote from: Warfley on April 22, 2022, 09:54:32 pm ---Some thing I've found, which I did not report as a bug yet, because I don't know if it is desired (as this might very well introduce a load of unwanted side effects), is that implicit specialization is not recognizing possible implicit casts:
--- End quote ---

Currently this is indeed by design as at least Delphi does not allow it either. And I personally prefer that we don't open that pandora's box... (especially es it might become problematic to determine what is a suitable specialization if there are multiple valid implicit assignments to do this in more complex scenarios)

corpsman:
Hello all,
the implicit generic specialization is exactly what i was searching for, but. In the usermanual of FPC 3.2.2 ( https://sourceforge.net/projects/freepascal/files/Documentation/3.2.2/ ) it is not listed anymore.

Also my FPC compiler

--- Quote ---corpsman@corpsman:~$ fpc -h
Free Pascal Compiler version 3.2.2+dfsg-9ubuntu1 [2022/04/11] for x86_64

--- End quote ---
Throws the message

--- Quote ---project1.lpr(4,2) Warning: Illegal compiler switch "IMPLICITFUNCTIONSPECIALIZATION+"

--- End quote ---
when i try to compile this:

--- 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";}};} ---program Project1;{$mode objfpc}{$H+} {$ModeSwitch implicitfunctionspecialization}begin end.  Did i miss something ?

Warfley:

--- Quote from: corpsman on October 04, 2024, 11:30:02 am ---Did i miss something ?

--- End quote ---

FPC 3.2.2 is from May 2021, this feature was introduced in 2022 to Trunk/Main so it will be only in the next major version. Also don't expect too much it has quite some limitations, so better be ready to still write "specialize ...<types>" for some time to come

dbannon:

--- Quote from: corpsman on October 04, 2024, 11:30:02 am ---Did i miss something ?

--- End quote ---

Yes, several posts further up, PascalDragon said -

New features are first available only in the development version (aka main) until the next major release (which will be 3.4.0 in some undetermined time in the future). So you'll have to clone the Git repository and compile FPC yourself. Or as is the hype nowadays: use FpcUpDeluxe.

3.4.0 release date is still undetermined.

Davo

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version