我可以为 FORTRAN 2003 中的派生数据类型重载条目访问运算符 []、() 或 {}?在以下示例中,我想为派生数据类型“自定义”定义访问方案。
type custom
integer, dimension(:), allocatable :: a
end type custom
type(custom) :: t
! after some initialization
! .....
! .....
! .....
!
t%a( (/ 1, 2, 5 /) ) ! return entries located in positions 1, 2, and 5
t{ (/ 1, 2, 5 /) } ! ?????? I want to define what stuff it should return
我怎样才能做到这一点?
更新:
请注意,我不想直接使用数组“t%a”并对其进行常规的子数组操作。相反,我想为数据类型“自定义”重新定义数组操作,这样 t{'first'} 应该返回一个指针,即 t%a 或 t%a(1) 中的第一个条目,所以我可以说
t['first']= 18
或者
print *, t['first'].
此外,通过额外的重载,我想获得像 t[1] = 18 这样的功能,就像 t['first'] = 18 一样。