copy must be const?!?
Dom DiSc
dominikus at scherkl.de
Fri Jul 26 08:27:11 UTC 2024
On Thursday, 25 July 2024 at 22:22:19 UTC, Quirin Schroll wrote:
> On Thursday, 25 July 2024 at 13:07:03 UTC, Jonathan M Davis
> wrote:
>> But either way, it would cause quite a few problems if IFTI
>> started instantiating templates in general with mutable
>> instead of the actual type that it's given, because it's
>> extremely common that const and immutable types cannot be
>> converted to mutable.
>
> It’s wild how C++ and D disagree on this one. In C++, a copy
> constructor must produce a mutable copy. Now, C++ and D
> disagree on what `const` means and therefore what counts as a
> mutable copy. But, and this is the key takeaway, C++ never
> infers `const` on a copy. Never. It does infer `const` on a
> reference, of course.
sigh.
One more point where C++ made better decisions.
> Nothing of this is out of reach for D. A type for which const
> objects can’t be copied to initialize a mutable one simply
> isn’t copyable and therefore can’t be passed by value. A type
> for which const rvalues can’t be used to initialize a mutable
> variable aren’t movable.
+1
> However, copying a type [with const] for which there’s a copy
> constructor that can give you a mutable object is a no-no.
That's my point.
More information about the Digitalmars-d-learn
mailing list