I would like to overload the int
intrinsic function so that int(.true.) = 1
and int(.false.) = 0
. Here is my implementation. Is it correct and standard-compliant? I have never tried overloading intrinsic functions. Thank you for suggestions and comments.
module int_mod
implicit none
private
public :: int
interface int
module procedure logical_to_int
end interface int
contains
pure elemental function logical_to_int(x) result(y)
implicit none
logical, intent(in) :: x
integer :: y
y = merge(tsource=1, fsource=0, mask=x)
end function logical_to_int
end module int_mod