Fortran-FOSS-Programmers / Fortran-FOSS-Programmers/FIAT

why transfer-trick instead of class(*)?

Open
#5 5 comments 0 reactions 5 assignees Claimed by @cmacmackin View on GitHub
enhancement help wanted question
Dominant language
Fortran
Stars
36
Forks
10
PR merge metrics
No merged PRs in 30d

Description

Hi @cmacmackin ,

I have restarted to study FIAT with hope to contribute to it. I am now going to develop an hash-table with the hope to merge into FIAT.

I am almost sure I have asked this already, but I do not remember your answer... sorry.

For your [abstract container](https://github.com/Fortran-FOSS-Programmers/FIAT/blob/master/src/abstract_container.F90) you encode data by transfer built-in, e.g.

``` fortran
type, public, abstract :: container
private
integer(i1), dimension(:), allocatable :: storage !! Variable in which to place data contents
logical :: filled = .false. !! `.true.` if container is set, `.false.` otherwise
contains
private
procedure(guard), deferred :: typeguard
...
end type container
```

I also used transfer-trick for generic list before `class(*)` becomes available in my main-stream compiler at that time. Now, I am wondering which are the advantages to prefer transfer-trick over the unlimited polymorphic data. For example I like to have the contained data defined as a **pointer** in order to avoid copy-in-copy-out every-time I manage the data (that in my application case could be large, order of 100MB). Moreover, you already use the `select type` cluttering-syntax for the `typeguard` method, thus the main cons of `class(*)` is already accomplished.

Currently, I am playing with something like

``` fortran
type, public, abstract :: container
private
class(*), pointer :: storage !! Variable in which to place data contents
logical :: filled = .false. !! `.true.` if container is set, `.false.` otherwise
contains
private
procedure(guard), deferred :: typeguard
procedure(associate_to_contents_interface), deferred :: associate_to_contents
...
end type container
```

where the `associate_to_contents` is similar to your `typeguard`, but performs only a pointer association.

I would like to know your opinions, in particular what you think are the main pros of transfer-trick over class(*).

Cheers.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.