Is it possible to take two polymorphic objects and determine if they are of the same derived type (or class)? The intention is to use it as a clean way to filter a generic linked list.
Something like the following mock code.
function isSameType(a, b) result(itIs)
!arguments
class(*), intent(in) :: a
class(*), intent(in) :: b
!output
logical :: itIs
!return true if a and b are both the same type
!return false if a and b are not
end function isSameType
The standard inquiry function
same_type_astests equality of dynamic type of two objects:same_type_asdoes not test declared type (except where this is the same thing). It does not consider kind parameters:Further, to get a useful result you'll be wanting (at least) one of
aandbto be of extensible dynamic type. While you can askthe result is processor dependent (could be true or false).