copy constructors need documentation
Olivier FAURE
couteaubleu at gmail.com
Tue Aug 6 08:35:29 UTC 2019
On Tuesday, 6 August 2019 at 07:53:25 UTC, RazvanN wrote:
> No. typeof(this) is going to be immutable(T) and `this` cannot
> be modified
> as in `this = something`, but the first assignment of each of
> this's field
> is considered initialization and allowed:
>
> struct T
> {
> int a;
> this(int a) immutable
> {
> pragma(msg, typeof(this)); // immutable(T)
> this.a = a; // ok, even though this.a
> is immutable
> }
> }
Makes sense.
By the way, weird edge cases like that are why I like Rust's
semantics (there's no constructor, just struct initialization and
factory functions).
Too bad there's no non-painful way to implement them in D at this
point.
More information about the Digitalmars-d
mailing list