Is all this Invarient **** er... stuff, premature optimisation?
Hans W. Uhlig
huhlig at gmail.com
Wed Apr 30 16:11:36 PDT 2008
e-t172 wrote:
> Lionello Lunesu a écrit :
>>
>> "Walter Bright" <newshound1 at digitalmars.com> wrote in message
>> news:48169E90.6050700 at digitalmars.com...
>>> Me Here wrote:
>>>> Janice Caron wrote:
>>>>> Functions don't overload on return value.
>>>> They don't? Why not? Seems like a pretty obvious step to me.
>>>
>>> Type inference in D is done "bottom up". Doing overloading based on
>>> function return type is "top down". Trying to get both schemes to
>>> coexist is a hard problem.
>>
>> But a function's result can be overloaded using "out", so why can't it
>> be overloaded using the return value?
>>
>> Can't the compiler treat a return value as an implicit out argument?
>
> Consider this:
>
> int foo();
> float foo();
>
> void bar(int a);
> void bar(float a);
>
> Then this:
>
> void main()
> {
> bar(foo());
> }
>
> There is an obvious problem here.
One of two things, make an assumption as to which is called by which has
the higher priority(based on precision or type). Or throw a compiler
error if no cast is made.
Overload Ambiguity, Cast Must be made when both return overload and
parameter overload types are ambigious.
More information about the Digitalmars-d
mailing list