File: operator_overloading_22.f90

package info (click to toggle)
lfortran 0.60.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 58,412 kB
  • sloc: cpp: 173,406; f90: 80,491; python: 17,586; ansic: 9,610; yacc: 2,356; sh: 1,401; fortran: 895; makefile: 37; javascript: 15
file content (62 lines) | stat: -rw-r--r-- 1,285 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
59
60
61
62
! Regression test for unary defined operator with elemental function
! Covers:
!  - OPERATOR(.rw.) defined via MODULE PROCEDURE
!  - ELEMENTAL function used in expression context
!  - Use inside another elemental function
!  - Use from main program

module operator_overloading_22_mod
    implicit none
    private

    public :: myt, afunc, operator(.rw.)

    type myt
        sequence
        integer :: x
        integer :: y
        integer :: z
    end type myt

    interface operator(.rw.)
        module procedure rw
    end interface

contains

    integer elemental function rw(t)
        implicit none
        type(myt), intent(in) :: t
        rw = 1
    end function rw

    logical elemental function afunc(t)
        implicit none
        type(myt), intent(in) :: t

        if (.rw. t <= 5) then
            afunc = .true.
        else
            afunc = .false.
        end if
    end function afunc

end module operator_overloading_22_mod


program operator_overloading_22
    use operator_overloading_22_mod
    implicit none

    type(myt) :: t
    logical :: z
    integer :: x

    t = myt(1, 2, 3)

    x = .rw. t
    z = afunc(t)

    print *, x
    print *, z
end program operator_overloading_22