const challenge
Russell Lewis
webmaster at villagersonline.com
Sun Feb 3 10:32:35 PST 2008
If we had a opImplicitCast (and it was overloadable), then it would be
pretty easy to implement a template with thunks:
template PolysemousContainer(A,B)
{
A delegate() thunk1;
B delegate() thunk2;
A opImplicitCast() { return thunk1(); }
B opImplicitCast() { return thunk2(); }
}
PolySemousContainer(A,B)
Polysemous(A,B)(A delegate() thunk1,
B delegate() thunk2)
{
PolysemousContainer!(A,B) ret;
ret.thunk1 = thunk1;
ret.thunk2 = thunk2;
return ret;
}
Walter Bright wrote:
> Janice Caron wrote:
>> On 2/2/08, Walter Bright <newshound1 at digitalmars.com> wrote:
>>> It can be solved by having the result type of ~ be a polysemous
>>> type, i.e. its type is based on how it is used.
>>
>> Will we be able to write our own functions which are declared to
>> return polysemous types?
>
> No. They're basically a hack.
More information about the Digitalmars-d
mailing list