Thread overview | ||||||
---|---|---|---|---|---|---|
|
January 20, 2015 What is the "Final"? | ||||
---|---|---|---|---|
| ||||
Alexandrescu "The_D_Programming_Language" page 264: 7.1.10 Subtyping with structs. The @disable Attribute import std.stdio; ... unittest { auto a = Final!Widget(new Widget); a.print(); // Fine, just print a auto b = a; // Fine, a and b are bound to the same Widget a = b; // Error! // opAssign(Finai!Widget) is disabled! a = new Widget; // Error! // Cannot assign to rvatue returned by get()! } What is the "Final" in the code? |
January 20, 2015 Re: What is the "Final"? | ||||
---|---|---|---|---|
| ||||
Posted in reply to RuZzz | On 21/01/2015 12:58 a.m., RuZzz wrote:
> Alexandrescu "The_D_Programming_Language"
> page 264: 7.1.10 Subtyping with structs. The @disable Attribute
> import std.stdio;
> ...
> unittest {
> auto a = Final!Widget(new Widget);
> a.print(); // Fine, just print a
> auto b = a; // Fine, a and b are bound to the same Widget
> a = b; // Error!
> // opAssign(Finai!Widget) is disabled!
> a = new Widget; // Error!
> // Cannot assign to rvatue returned by get()!
> }
>
> What is the "Final" in the code?
I'm guessing something along these lines:
struct Final(T) {
private T value;
alias value this;
this(T value) {
this.value = value;
}
@disable
void opAssign(T)(T t) {}
}
|
January 20, 2015 Re: What is the "Final"? | ||||
---|---|---|---|---|
| ||||
Posted in reply to RuZzz | Probably borrowed from java: http://docs.oracle.com/javase/specs/jls/se8/html/jls-4.html#jls-4.12.4 |
January 20, 2015 Re: What is the "Final"? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Rikki Cattermole | Rikki Cattermole: > I'm guessing something along these lines: A Phobos patch: https://github.com/D-Programming-Language/phobos/pull/2881 Bye, bearophile |
Copyright © 1999-2021 by the D Language Foundation