Reputation: 1525
I am a bit confused as I am running my code to do scalar-vector multiplication using u = v * scalar and v = scalar * u
I thought the following code would give me ambiguous declaration for the generic '*'. How are the functions vsm_real32, vsm_real64, and vsm_real128 not conflicting with function svm?
Procedure :: vsm_real32, vsm_real64, &
vsm_real128
Procedure, Pass (tb) :: svm
Generic :: Operator (*) => vsm_real32, &
vsm_real64, vsm_real128, &
svm
Contains
Function vsm_real32 (tb, sc_real32) Result (ta)
Type (Vector) :: ta
Class (Vector), Intent (In) :: tb
Real (Real32), Intent (In) :: sc_real32
Call vsmd (ta, tb, sc_real32, "*")
End Function vsm_real32
Function vsm_real64 (tb, sc_real64) Result (ta)
Type (Vector) :: ta
Class (Vector), Intent (In) :: tb
Real (Real64), Intent (In) :: sc_real64
Call vsmd (ta, tb, sc_real64, "*")
End Function vsm_real64
Function vsm_real128 (tb, sc_real128) Result (ta)
Type (Vector) :: ta
Class (Vector), Intent (In) :: tb
Real (Real128), Intent (In) :: sc_real128
Call vsmd (ta, tb, sc_real128, "*")
End Function vsm_real128
Function svm (sc, tb) Result (ta)
Type (Vector) :: ta
Class (*), Intent (In) :: sc
Class (Vector), Intent (In) :: tb
Call vsmd (ta, tb, sc, "*")
End Function svm
Upvotes: 2
Views: 351
Reputation: 21431
The generic binding is for an operator. The requirement for procedures to be distinguishable is based on the position of the dummy arguments only.
(For the expression a * b
, the first dummy argument always corresponds to a
, the second to b
. Passed arguments don't influence disambiguation in this case.)
The vsm_*
functions all have a required second dummy argument that varies in real kind from function to function. That second argument is therefore distinguishable, therefore the vsm_*
functions are all distinguishable.
The second argument of svm function is of type Vector
. This is a different type to the type of the second argument of the vsm_*
functions (REAL), therefore the second argument is distinguishable, therefore the svm
function is distinguishable from all of the vsm_*
functions.
Refer F2008 C1212.
Upvotes: 3