[phobos] Design question - is return type Algebraic?
Shin Fujishiro
rsinfu at gmail.com
Fri Jul 9 10:17:00 PDT 2010
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). 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. Furthermore, we can't do the following if a result is
packed in an Algebraic:
----------
void fun(R)(R r) if (isSomeChar!(ElementType!R))
{
}
Algebraic!(string, CharReader) r;
r = "abc";
fun(r); // Error! ElementType is Algebraic!(dchar)
----------
Too bad, Algebraic r is not a 'duck' anymore.
I'm stucked. Do you have any ideas?
Shin
More information about the phobos
mailing list