Introduction
COLLECTIONS is a library providing a set of types supporting collections in Fortran. The collection types within this library are object-oriented by design, and utilize Fortran's unlimited polymorphic variable functionallity allowing storage of any data type.
This library relies upon the FERROR library to provide a mechanism for communicating any runtime errors that may occur while using this library.
- Example
- One of the collection types this library provides is a generic, dynamically sizeable type referred to simply as list. A simple example illustrating basic usage of the list type is as follows.
program list_example
use iso_fortran_env
implicit none
integer(int32), parameter :: n = 10
integer(int32) :: i
type(list) :: x
class(*), pointer :: ptr
do i = 1, n
call x%push(2 * i)
end do
print '(A)', "***** Original List *****"
do i = 1, n
ptr => x%get(i)
select type (ptr)
type is (integer(int32))
print *, ptr
end select
end do
call x%insert(5, 100)
print '(A)', new_line('a') // "***** After Insertion *****"
do i = 1, x%count()
ptr => x%get(i)
select type (ptr)
type is (integer(int32))
print *, ptr
end select
end do
A module containing various collections using Fortran's unlimited polymorphic functionallity.
This program generates the following output.
***** Original List *****
2
4
6
8
10
12
14
16
18
20
***** After Insertion *****
2
4
6
8
100
10
12
14
16
18
20