在 Fortran 中重载箭头运算符 (=>)

Overload arrow operator (=>) in fortran

我刚开始在 Fortran 2003 中重载运算符(包括赋值),我想为我的用户定义类型重载箭头运算符 (=>)。 我知道对于大多数运算符,比如 (+),我会说

interface operator(+)  
    ! What I want this to mean instead  
end interface operator

但是,这不适用于 (=>)。我知道作业,我会说

interface assignment(=)  
    ! What I want this to mean instead  
end interface assignment

仍然不适用于 (=>)。

具体来说,我定义了一个底层数据是指针的类型。

type my_type
    integer, pointer :: data(:)
end type my_type

所以,当我说

type (my_type) :: a
integer, target :: b(4)

! Do stuff to b
a => b

我想这意味着

a%data => b

感谢您的任何建议! 2003 标准以外的标准答案也会有所帮助。

无法在 Fortran 2018 中重载指针赋值。

This question 询问是否使用类型绑定过程来处理重载,但在更一般的意义上,答案仍然是否定的。

截至Fortran 2018,指针赋值语句的含义

a => b

总是影响左边指针a的指针状态。

尽管 Fortran 标准有 intrinsicdefined 赋值(后者随 interface assignment(=) 引入),但没有这样的指针赋值的区别。