Overloading based on attributes - is it a good idea?

Manu turkeyman at gmail.com
Fri May 31 21:39:10 UTC 2019


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

...?



More information about the Digitalmars-d mailing list