EXTENDS_TYPE_OF(3) - [STATE:INQUIRY] Determine if the dynamic type of A is an extension of the dynamic type of MOLD.
result = extends_type_of(a, mold)
logical extends_type_of(a, mold)type(TYPE(kind=KIND)),intent(in) :: a type(TYPE(kind=KIND)),intent(in) :: mold
-A shall be an object or pointer to an extensible declared type, or unlimited polymorphic. If it is a polymorphic pointer, it shall not have an undefined association status. -MOLE shall be an object or pointer to an extensible declared type or unlimited polymorphic. If it is a polymorphic pointer, it shall not have an undefined association status.
o the result is a scalar default logical type.
EXTENDS_TYPE_OF(3) is .true. if and only if the dynamic type of A is or could be (for unlimited polymorphic) an extension of the dynamic type of MOLD.
NOTE1
The dynamic type of a disassociated pointer or unallocated allocatable variable is its declared type.
NOTE2
The test performed by EXTENDS_TYPE_OF is not the same as the test performed by the type guard CLASS IS. The test performed by EXTENDS_TYPE_OF does not consider kind type parameters.
o A : be an object of extensible declared type or unlimited polymorphic. If it is a polymorphic pointer, it shall not have an undefined association status. o MOLD : be an object of extensible declared type or unlimited polymorphic. If it is a polymorphic pointer, it shall not have an undefined association status.
If MOLD is unlimited polymorphic and is either a disassociated pointer or unallocated allocatable variable, the result is true.
Otherwise if A is unlimited polymorphic and is either a disassociated pointer or unallocated allocatable variable, the result is false.
Otherwise the result is true if and only if the dynamic type of A
if the dynamic type of A or MOLD is extensible, the result is true if and only if the dynamic type of A is an extension type of the dynamic type of MOLD; otherwise the result is processor dependent.
Sample program:
! program demo_extends_type_of module M_demo_extends_type_of implicit none privateResults:type nothing end type nothing
type, extends(nothing) :: dot real :: x=0 real :: y=0 end type dot
type, extends(dot) :: point real :: z=0 end type point
type something_else end type something_else
public :: nothing public :: dot public :: point public :: something_else
end module M_demo_extends_type_of
program demo_extends_type_of use M_demo_extends_type_of, only : nothing, dot, point, something_else implicit none type(nothing) :: grandpa type(dot) :: dad type(point) :: me type(something_else) :: alien
write(*,*)these should all be true write(*,*)extends_type_of(me,grandpa),I am descended from Grandpa write(*,*)extends_type_of(dad,grandpa),Dad is descended from Grandpa write(*,*)extends_type_of(me,dad),Dad is my ancestor
write(*,*)is an object an extension of itself? write(*,*)extends_type_of(grandpa,grandpa) ,self-propagating! write(*,*)extends_type_of(dad,dad) ,clone!
write(*,*) you did not father your grandfather write(*,*)extends_type_of(grandpa,dad),no paradox here
write(*,*)extends_type_of(dad,me),no paradox here write(*,*)extends_type_of(grandpa,me),no relation whatsoever write(*,*)extends_type_of(grandpa,alien),no relation write(*,*)extends_type_of(me,alien),not what everyone thinks
call pointers() contains
subroutine pointers() ! Given the declarations and assignments type t1 real c end type type, extends(t1) :: t2 end type class(t1), pointer :: p, q allocate (p) allocate (t2 :: q) ! the result of EXTENDS_TYPE_OF (P, Q) will be false, and the result ! of EXTENDS_TYPE_OF (Q, P) will be true. write(*,*)(P,Q),extends_type_of(p,q),"mind your Ps and Qs" write(*,*)(Q,P),extends_type_of(q,p) end subroutine pointers
end program demo_extends_type_of
> these should all be true > T I am descended from Grandpa > T Dad is descended from Grandpa > T Dad is my ancestor > is an object an extension of itself? > T self-propagating! > T clone! > you did not father your grandfather > F no paradox here > F no paradox here > F no relation whatsoever > F no relation > F not what everyone thinks > (P,Q) F mind your Ps and Qs > (Q,P) T
Fortran 2003
SAME_TYPE_AS(3)
Fortran intrinsic descriptions (license: MIT) @urbanjost
Nemo Release 3.1 | extends_type_of (3fortran) | November 02, 2024 |