Skip to content

why transfer-trick instead of class(*)? #5

Description

@szaghi

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 you encode data by transfer built-in, e.g.

  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

  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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions