File: operator_overloading_29.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 (37 lines) | stat: -rw-r--r-- 802 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
! Test type-bound operator(*) with pass(self) on the right operand
module module_operator_overloading_29
  implicit none

  type :: type_a
    double precision :: val
  end type

  type :: type_b
    double precision :: val
  contains
    procedure, pass(self) :: multiply_ab
    generic :: operator(*) => multiply_ab
  end type

contains

  pure function multiply_ab(a, self) result(c)
    type(type_a), intent(in) :: a
    class(type_b), intent(in) :: self
    type(type_a) :: c
    c%val = a%val * self%val
  end function

end module

program operator_overloading_29
  use module_operator_overloading_29
  implicit none
  type(type_a) :: a, res
  type(type_b) :: b
  a = type_a(2.0d0)
  b = type_b(3.0d0)
  res = a * b
  if (abs(res%val - 6.0d0) > 1.0d-10) error stop
  print *, res%val
end program