| Anonymous | Login | Signup for a new account | 2013-06-18 23:36 CEST | ![]() |
| All Projects | FPC | Lazarus: Packages, Patches | Lazarus CCR | Mantis | fpGUI | fpcprojects: fpprofiler |
| Main | My View | View Issues | Change Log | Roadmap |
| View Issue Details [ Jump to Notes ] | [ Issue History ] [ Print ] | ||||||||
| ID | Project | Category | View Status | Date Submitted | Last Update | ||||
| 0020854 | FPC | Compiler | public | 2011-12-09 10:50 | 2013-02-26 21:20 | ||||
| Reporter | Marco van de Voort | ||||||||
| Assigned To | Sven Barth | ||||||||
| Priority | normal | Severity | feature | Reproducibility | have not tried | ||||
| Status | resolved | Resolution | fixed | ||||||
| Platform | OS | OS Version | |||||||
| Product Version | Product Build | ||||||||
| Target Version | Fixed in Version | 2.7.1 | |||||||
| Summary | 0020854: Generic constraints | ||||||||
| Description | Delphi allows to specify constraints with generics. type xx<t:constraint1,constraint2> = class ... Constraints can be classtypes, interfacetypes and special cases "class","record" and "constructor", separated with comma's like interfaces. Constructor means that the class has a constructor without parameters, and allows generic code to call a constructor on a type T. Class means that it is a reference type (class or interface), probably important for typecasting relating to inheritance. record means it is a value type | ||||||||
| Tags | generics | ||||||||
| FPCOldBugId | 0 | ||||||||
| Fixed in Revision | 23158 | ||||||||
| Attached Files | |||||||||
Relationships |
||||||
|
||||||
Notes |
|
|
(0054865) Sven Barth (manager) 2011-12-09 14:08 |
Constraints are already on my ToDo list. I just don't know whether I first implement constraints or generic functions :) Regards, Sven |
|
(0054870) Marco van de Voort (manager) 2011-12-09 14:58 |
Since I don't use generic functions yet, I vote for constraints :-) Though the images bit (from which the alias bugreports are extracted) is more important to me than this pool stuff. |
|
(0054880) Alexander Shishkin (reporter) 2011-12-09 23:53 |
I think that generic functions are more priority. Delphi code with constrains can be compiled with FPC using ifdefs around them, and will work as expected (!) But I have no idea now to make code with generic functions portable to fpc without being fully rewritten. |
|
(0059544) Anthony Walter (reporter) 2012-05-13 00:14 |
Adding constraints won't improve functionality. Constraints would be nice, but the way FPC handles generics in some ways is much superior to the current Delphi implementation or even the C# implementation, in my opinion. I think the way FPC generics work now is like C++ templates, which are code generators. The generated code is checked against the types at compile time allowing us to write something like: function TMyClass<T>.Add(const A, B: T): T; begin Result := A + B; end; The above is not possible in Delphi or C#, but the above is HIGHLY desirable. It's exactly because the code above won't work in Delphi or C# why those languages have generic constraints. The constraints relax those compilers to allow call specific methods of T to be invoked. But currently FPC generics will figure it methods of T exist at compile time without the need for constraints and this is a good thing. As such, the only reason I see to add constraints is to make FPC code more compatible with Delphi. |
|
(0059578) Sven Barth (manager) 2012-05-14 12:49 |
Constraints are useful if you have certain expectations about the type. Consider FPC's TFPGObjectList. Currently you can specialize it using every type, but once constraints are added the declaration can be changed to "TFPGObjectList<T: class> = class ... end;" so that it is clear that only descendants of TObject can be used for a specialization (the compiler will enforce this). This also allows the compiler to do more checks while parsing the generic instead of when specializing. Regards, Sven |
|
(0064334) Sven Barth (manager) 2012-12-16 15:11 |
Please test and close if okay. Regards, Sven |
Issue History |
|||
| Date Modified | Username | Field | Change |
| 2011-12-09 10:50 | Marco van de Voort | New Issue | |
| 2011-12-09 10:50 | Marco van de Voort | File Added: basepool.pas | |
| 2011-12-09 10:50 | Marco van de Voort | FPCOldBugId | => 0 |
| 2011-12-09 14:08 | Sven Barth | Note Added: 0054865 | |
| 2011-12-09 14:58 | Marco van de Voort | Note Added: 0054870 | |
| 2011-12-09 22:43 | Florian | Severity | minor => feature |
| 2011-12-09 23:53 | Alexander Shishkin | Note Added: 0054880 | |
| 2011-12-11 11:48 | Paul Ishenin | Tag Attached: generics | |
| 2012-05-09 16:44 | Marco van de Voort | Description Updated | |
| 2012-05-13 00:14 | Anthony Walter | Note Added: 0059544 | |
| 2012-05-14 12:49 | Sven Barth | Note Added: 0059578 | |
| 2012-06-01 14:14 | Sven Barth | Relationship added | related to 0019491 |
| 2012-06-01 14:15 | Sven Barth | Status | new => acknowledged |
| 2012-12-16 15:11 | Sven Barth | Fixed in Revision | => 23158 |
| 2012-12-16 15:11 | Sven Barth | Status | acknowledged => resolved |
| 2012-12-16 15:11 | Sven Barth | Fixed in Version | => 2.7.1 |
| 2012-12-16 15:11 | Sven Barth | Resolution | open => fixed |
| 2012-12-16 15:11 | Sven Barth | Assigned To | => Sven Barth |
| 2012-12-16 15:11 | Sven Barth | Note Added: 0064334 | |
| Main | My View | View Issues | Change Log | Roadmap |



