Problem with immutables and Template typeof(this)
ketmar via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Dec 28 14:23:32 PST 2014
On Sun, 28 Dec 2014 14:07:18 -0800
AuoroP via Digitalmars-d-learn <digitalmars-d-learn at puremagic.com>
wrote:
let me give you a riddle:
struct ExampleTemplate(T) {
T value;
auto opAdd (typeof(this) that) inout {
import std.traits : Unqual;
Unqual!(typeof(this)) result;
result.value = this.value+that.value;
return result;
}
}
alias ExampleTemplate!int Example;
void main () {
immutable immutableEx = Example(1);
Example ex = Example(1);
Example ex2 = immutableEx+ex;
}
i tend to give some explanations to my answers here, but i'm in a
strange mood today, so sorry, no explanations this time.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20141229/94b1363b/attachment-0001.sig>
More information about the Digitalmars-d-learn
mailing list