Simple way to implement a group of queues in Fortran?

后端 未结 3 887
旧巷少年郎
旧巷少年郎 2021-01-16 18:57

Suppose that I need to implement at least 5 queues in one procedure, each of it from a different defined type. How can achive this in a simple and short way?.

Anot

3条回答
  •  遥遥无期
    2021-01-16 19:31

    I have implemented the fortran template in Ruby, which is integrated in my CodeMate. The template syntax is similar to C++. I have implemented double linked list. The template definition snippets are as following:

    ...
    
    template:list_t 
    type list_t
        integer :: num_elem = 0
        type(elem_t), pointer :: head, tail
    contains
        ...
        procedure :: insert => list_insert
        ...
    end type list
    
    ...
    
    template:list_insert@list_t 
    subroutine list_insert(this, elem, ...)
    
        class(list_t), intent(inout) :: this
        type(elem_t), intent(out), pointer :: elem
    
        ...
    
    end subroutine list_insert
    

    And the template instance is as following:

    type(list_t) foo_list
    

    where foo_t is a user-defined type that extends list_elem_t. The you can insert element into foo_list by

    call foo_list%insert(elem, ...)
    

    I think my solution to Fortran template is natural.

提交回复
热议问题