www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - isCopyable and isAssignable

reply =?UTF-8?B?Tm9yZGzDtnc=?= <per.nordlow gmail.com> writes:
Now that we have isCopyable from

https://github.com/dlang/phobos/pull/4706

can somebody briefly outline when something fulfills `isCopyable` 
but not `isAssignable` and vice versa?
Oct 09 2016
next sibling parent reply James Buren <ryu0 ymail.com> writes:
On Sunday, 9 October 2016 at 07:23:05 UTC, Nordl├Âw wrote:
 Now that we have isCopyable from

 https://github.com/dlang/phobos/pull/4706

 can somebody briefly outline when something fulfills 
 `isCopyable` but not `isAssignable` and vice versa?
I would imagine that an intermediate value, or other lvalue, may be copyable, but not assignable.
Oct 09 2016
parent Jonathan M Davis via Digitalmars-d-learn writes:
On Sunday, October 09, 2016 07:27:38 James Buren via Digitalmars-d-learn 
wrote:
 On Sunday, 9 October 2016 at 07:23:05 UTC, Nordl÷w wrote:
 Now that we have isCopyable from

 https://github.com/dlang/phobos/pull/4706

 can somebody briefly outline when something fulfills
 `isCopyable` but not `isAssignable` and vice versa?
I would imagine that an intermediate value, or other lvalue, may be copyable, but not assignable.
Yes, but isCopyable is checking a type, not a value, so that doesn't enter into it. To check any kind of value with isCopyable, you'd have to use typeof on it. - Jonathan M Davis
Oct 09 2016
prev sibling parent Jonathan M Davis via Digitalmars-d-learn writes:
On Sunday, October 09, 2016 07:23:05 Nordl÷w via Digitalmars-d-learn wrote:
 Now that we have isCopyable from

 https://github.com/dlang/phobos/pull/4706

 can somebody briefly outline when something fulfills `isCopyable`
 but not `isAssignable` and vice versa?
If it's const or immutable, it could be copyable but not assignable. Also, someone could specifically disable opAssign while still allowing copying, though I don't know why anyone would want to do that. As for the reverse, disabling the postblit constructor would disable copying, and if opAssign takes its argument by ref, then assignment should still work (though I'm not sure whether it would still work if you didn't explicitly overload opAssign). - Jonathan M Davis
Oct 09 2016