File: template_array_01.f90

package info (click to toggle)
lfortran 0.45.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 46,332 kB
  • sloc: cpp: 137,068; f90: 51,260; python: 6,444; ansic: 4,277; yacc: 2,285; fortran: 806; sh: 524; makefile: 30; javascript: 15
file content (58 lines) | stat: -rw-r--r-- 1,199 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
module template_array_01_m

    implicit none
    private
    public :: test_template

    requirement r(t)
        type, deferred :: t
    end requirement

    template array_tmpl(t)
        require :: r(t)
        private
        public :: insert_t
    contains
        function insert_t(lst, i) result(r)
            type(t), intent(in) :: lst(:), i
            type(t) :: r
            lst(1) = i
            r = lst(1)
        end function

        function insert_t_n(n, lst, i) result(r)
            integer, intent(in) :: n
            type(t), intent(in) :: lst(n), i
            type(t) :: r
            lst(1) = i
            r = lst(1) 
        end function
    end template

contains

    subroutine test_template()
        instantiate array_tmpl(integer), only: insert_int => insert_t, insert_int_n => insert_t_n
        integer :: a(1), i, r
        a(1) = 0
        i = 1
        print *, a(1)
        r = insert_int(a, i)
        print *, a(1)

        a(1) = 0
        print *, a(1)
        r = insert_int_n(size(a), a, i)
        print *, a(1)
    end subroutine

end module

program template_array_01

    use template_array_01_m
    implicit none

    call test_template()

end