File: operator_overloading_03.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 (53 lines) | stat: -rw-r--r-- 1,484 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
module operator_overloading_01_overload_comp_m
    implicit none
    public operator (>)

    interface operator (>)
        module procedure greater_than_inverse
    end interface

    interface operator (<)
        module procedure less_than_inverse
    end interface
contains
    pure logical function greater_than_inverse(log1, log2)
        logical, intent (in) :: log1, log2

        if( log1 .eqv. .true. .and. log2 .eqv. .false. ) then
            greater_than_inverse = .true.
        else
            greater_than_inverse = .false.
        end if
    end function

    pure logical function less_than_inverse(log1, log2)
        logical, intent (in) :: log1, log2

        if( log1 .eqv. .false. .and. log2 .eqv. .true. ) then
            less_than_inverse = .true.
        else
            less_than_inverse = .false.
        end if
    end function

    pure logical function less_than_overload_use(log1, log2)
        logical, intent (in) :: log1, log2

        less_than_overload_use = log1 < log2
    end function
end module

program operator_overloading_01
  use operator_overloading_01_overload_comp_m
  implicit none
  logical, parameter :: T = .true., F = .false.

  print *, "T>T:", T>T  ! Yields: F
  print *, "T>F:", T>F  ! Yields: F
  print *, "F>T:", F>T  ! Yields: T
  print *, "F>F:", F>F  ! Yields: F
  print *, "T<T:", T<T  ! Yields: F
  print *, "T<F:", T<F  ! Yields: T
  print *, "F<T:", F<T  ! Yields: F
  print *, "F<F:", F<F  ! Yields: F
end program