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
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 elem_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 <type elem_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_t>) foo_list
where foo_t
is a user-defined type that extends list_elem_t<foo_t>
. The you can insert element into foo_list
by
call foo_list%insert(elem, ...)
I think my solution to Fortran template is natural.
Have you considered unlimited polymorphic pointers? See, for ex., pp 269 ff in "Modern Fortran Explained".
If you really want templates, there is Pyf95++. It brings templating and an STL for Fortran using a preprocessor. (for download here)
A generic linked-list that uses transfer()
can be found in FLIBS.
(Otherwise with a bleeding edge compiler you can use unlimited polymorphism as suggested by Richard Lozes.)