[phobos] Design question - is return type Algebraic?

Andrei Alexandrescu andrei at erdani.com
Fri Jul 9 10:27:11 PDT 2010


On 07/09/2010 12:17 PM, Shin Fujishiro wrote:
> My Any implementation used auto ref for return types.  But it turned
> out to be too restrictive for Algebraic.  Consider this:
> ----------
> Algebraic!(int, BigInt) x;
> auto y = ++x;
> // Error: mismatched function return type inference of BigInt and int
> ----------
>
> Maybe operator overloads should return Algebraic!(int, BigInt).

Yes, agreed. I actually would like all overloaded operators to return 
void and have the language insert a reference to the object if needed.

> Then,
> should we do the same for opDispatch() for unity?
> ----------
> Algebraic!(R1, R2, ...) opDispatch(string method, Args...)(Args args)
> {
>      final switch (_which) {
>          case A: return Algebraic( objA.method(args) );
>          case B: return Algebraic( objB.method(args) );
>          ...
>      }
> }
> ----------
>
> I'm a bit reluctant to do so.  Returning Algebraic disables return-by-
> ref facility.

Agreed. I think it should return CommonType!(R1, R2, ...). In the 
particular case in which all R1, R2, ... are identical AND returned by 
reference, only then you can return ref R1.


Andrei


More information about the phobos mailing list