Interior immutability and rvalues
maik klein via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Jul 15 01:29:56 PDT 2016
There are two things that bothered me for quite some time
Interior immutability:
Consider a something like this
https://dpaste.dzfl.pl/fa5be84d26bc
The implementation is totally wrong and it doesn't make sense,
but it shows that Rc can not be const/immutable because at least
"dup" needs to increment the counter.
Is it possible to express that Rc should be mutable but the value
that it wraps should be either mutable or const/immutable?
Rvalues and forwarding:
The problem is that when you pass an rvalue to a function you
lose the information that is an rvalue. There is nothing like
std::forward from c++ that I am aware of.
That becomes a problem when I use variadics with non copyable
types. I need to call move on types that can not be copied.
I guess what I could do is to use
https://dlang.org/phobos/std_traits.html#hasElaborateCopyConstructor to detect which types in the variadic args are actually non copyable and then call .move on them.
Is this how you would do it? The use case would be something like
this
void test(Args...)(Args args){
someOtherTest(args); // doesn't work because args contains
some non copyable types
}
void test(Args...)(Args args){
someOtherTest(mixin forward!(args));
}
//expands to
void test(Args...)(Args args){
someOtherTest(args[0].move, args[1], args[2]);
}
More information about the Digitalmars-d-learn
mailing list