Disclaimer: The "discovery" I'm about to describe here seems so obvious that I'm inclined to think that I've made some mistake.

The sole purpose of postblit constructors is to provide value semantics to structs which have mutable indirection (variables which have only immutable indirection have value semantics implicitly). Variables that are const/immutable can't have mutable indirection. Therefore, when making a copy from a const/immutable variable to a const/immutable variable, there's no need to call the postblit constructor.

Example:

----
struct S
{
    int[] values;

    this(this)
    {
        values = values.dup;
    }
}

void foo(const S) { }

void main()
{
    const S s;
    foo(s); // No need to call postblit
}

Reply via email to