pass by value && elide dtor + post-blit
Ali Çehreli via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Jun 20 15:44:15 PDT 2015
On 06/20/2015 02:09 PM, Xiaoxi wrote:
> When passing a struct by value:
>
> Is there any way to trick the compiler to elide unnecessary post-blit &
> dtor pair?
>
> Maybe using an union, somehow?
>
Can you show with an example please. I don't see either of those called
for the following program:
import std.stdio;
struct S
{
this(int)
{
writeln(__FUNCTION__);
}
this(this)
{
writeln(__FUNCTION__);
}
~this()
{
writeln(__FUNCTION__);
}
}
S foo()
{
auto s = S(42);
return s;
}
void main()
{
writeln("before");
auto s = foo();
writeln("after");
}
The output:
before
deneme.S.this
after
deneme.S.~this
Ali
More information about the Digitalmars-d-learn
mailing list