Closed weixing1531 closed 3 years ago
I think conceptually there is quite a big difference between an unlimited polymorphic list (aka class(*)
) and a list template that has to be instantiated for a particular type. IMHO the class(*)
does not really replace the template, in the sense that in all cases where you know the stored type beforehand, you would not want to use the class(*)
list: There would be a bit of overhead (likely irrelevant if you are using a linked list in the first place), but you also need to sprinkle select types all over your code, whereever you want to access elements from the list.
I did experiment a bit with an ftlList that can store instances of a class and classes derived from it, see the code on this branch: https://github.com/SCM-NV/ftl/blob/polymorphic_ftlList/tests/ftlListTests.F90#L700 It can be triggered with FTL_TEMPLATE_TYPE_IS_CLASS. It seems an attractive feature to have for ftlList and the other containers where this is technically possible (ftlHashMap, ftlHashSet), but I don't see it as a replacement for lists of a fixed type. I didn't try yet, if I can use this directly with class(*), or if this causes other problems.
I wrote a file named ftlListMod.F90 replacing ftlList.F90_template. I used "class(*)" instead of FTL_TEMPLATE_TYPE_WRAP. Then, the new program can achieve the same function without macros.
ftlListMod.F90.txt test.F90.txt https://github.com/weixing1531/ftlList