File: operator_overloading_31.f90

package info (click to toggle)
lfortran 0.61.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 61,892 kB
  • sloc: cpp: 181,767; f90: 92,175; python: 17,616; ansic: 10,170; yacc: 2,377; sh: 1,444; fortran: 892; makefile: 38; javascript: 15
file content (46 lines) | stat: -rw-r--r-- 1,086 bytes parent folder | download | duplicates (2)
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
module operator_overloading_31_m1
    implicit none
    private
    public :: t, operator(==)
    type :: t
        integer :: v
    end type
    interface operator(==)
        module procedure t_eq
    end interface
contains
    pure logical function t_eq(a, b)
        type(t), intent(in) :: a(:), b(:)
        t_eq = all(a%v == b%v)
    end function
end module

module operator_overloading_31_m2
    use operator_overloading_31_m1, only: t, operator(==)
    implicit none
    private
    public :: t, operator(==)
end module

module operator_overloading_31_m3
    use operator_overloading_31_m2
    implicit none
contains
    logical function compare(a, b)
        type(t), intent(in) :: a(:), b(:)
        compare = (a == b)
    end function
end module

program operator_overloading_31
    use operator_overloading_31_m1
    use operator_overloading_31_m3
    implicit none
    type(t) :: x(2), y(2), z(2)
    x = [t(1), t(2)]
    y = [t(1), t(2)]
    z = [t(3), t(4)]
    if (.not. compare(x, y)) error stop
    if (compare(x, z)) error stop
    print *, compare(x, y)
end program