Overloading based on attributes - is it a good idea?
Simen Kjærås
simen.kjaras at gmail.com
Fri May 31 22:22:29 UTC 2019
On Friday, 31 May 2019 at 21:39:10 UTC, Manu wrote:
> On Fri, May 31, 2019 at 11:35 AM Ola Fosheim Grøstad via
> Digitalmars-d <digitalmars-d at puremagic.com> wrote:
>>
>> On Friday, 31 May 2019 at 17:52:28 UTC, Manu wrote:
>> > out params. wrapping return values kinda sucks, inhibits RVO.
>>
>> It can, yes. It requires more advanced RVO optimizations to
>> avoid it.
>>
>> > overloading on return value seems problematic... how would
>> > that work?
>>
>> The compiler narrows down possible return types until one is
>> left. The simple version would require an explicit type, a
>> more advanced version would look at how the result is used and
>> use that to narrow down the candidate types until one is left.
>
> A fun() { return A(); }
> B fun() { return B(); }
>
> fun(); // <- return value ignored
>
> ...?
Ambiguous. cast(A)fun(); to call that specific overload. I guess
that means cast(void)cast(A)fun(); if fun is pure...
--
Simen
More information about the Digitalmars-d
mailing list