does cast make an lvalue appear to be an rvalue
Daniel Davidson
nospam at spam.com
Wed Oct 16 13:25:17 PDT 2013
On Wednesday, 16 October 2013 at 19:49:25 UTC, monarch_dodra
wrote:
> On Wednesday, 16 October 2013 at 17:50:48 UTC, Daniel Davidson
> wrote:
>> How do you propose to make a mutable copy *generically*?
>
> You can't. Let alone generically.
>
> If I give you an "immutable int* p", how do you copy it to
> "int* p" ?
>
> On Wednesday, 16 October 2013 at 18:11:48 UTC, Daniel Davidson
> wrote:
>> Thanks. It is cute - but not so helpful. The example stands. I
>> *need* to call a createRFromT.
>>
>> Their shapes are the same in this simple example because I
>> simplified. Make R look like:
>>
>> struct R {
>> string[string] ss;
>> int[] j;
>> }
>>
>> and the cute trick falls apart. In words, I have an R and I
>> want to make a T. The R is const the T will be immutable
>> because the ctor requires it. But it is technically not
>> immutable until it is initialized.
>
> The problem is that you are taking a const(R). And you can't
> assign a const to an immutable. It has nothing to do with
> initialization.
Just to clarify: in the code below: createRFromT(t, r) is *not*
meant to imply it will just try an assignment. Rather, it reads
from t and builds its own data for R. The problem is with
initialization - see Simen Kjaeraas response here:
http://forum.dlang.org/post/mailman.2241.1381953340.1719.digitalmars-d-learn@puremagic.com
struct S {
R r;
this(ref const(T) t) immutable {
createRFromT(t, r);
}
}
void createRFromT(ref const(T) t, ref R r) {
//...
}
More information about the Digitalmars-d-learn
mailing list