2013/5/16 Don Clugston <dclugston@gmail.com>
On 15 May 2013 23:19, Andrei Alexandrescu <andrei@erdani.com> wrote:
I'm not assuming you're proposing this, but I'm clarifying just in case: a member that takes per-instance memory YET always has the same value in all objects would be positively useless. _That_ should at best be an error.

Great! This is exactly my argument. In that case we are actually in agreement. Thats the case I want to disallow.

Why it should be error? Yes, it would be finally redundant, but the redundancy is necessary to keep meta-programming simple.

import std.traits;
struct MyData(T) if (isIntegral!T) {
    T value = 10;   // provides default value
    alias value this;
    this(T v) { value = v; }
}

With 2.062 and earlier, this simple MyData struct did not work when T is non-mutable integer type. To support it, it had been required that checking T is non-mutable and then remove constructor.

import std.traits;
struct MyData(T) if (isIntegral!T) {
    T value = 10;   // provides default value
    alias value this;
    static if (!is(T == const) && !is(T == immutable))
    {   // necessary for 2.062 and earlier
        this(T v) { value = v; }
    }
}

This is definitely unnecessary complexity. Why you need this?

D should have ability for writing efficient code, but D should not enforce writing efficient code to users.

Kenji Hara