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

Reply via email to