March 17, 2005 Mixins and operator overloading | ||||
---|---|---|---|---|
| ||||
import std.stdio; class A { A opCatAssign(int[] arr) { foreach(int v; arr) writefln(v); return this; } } class B { template opCatAssign(Type) { B opCatAssign(Type arr) { foreach(typeof(arr[0]) v; arr) writefln(v); return this; } } mixin opCatAssign!(int[]); } void main() { static int[] arr = [0,1,2]; A a = new A(); B b = new B(); a ~= arr; b ~= arr; //Error: Can only concatenate arrays } Regan |
March 22, 2005 Re: Mixins and operator overloading | ||||
---|---|---|---|---|
| ||||
Posted in reply to Regan Heath | -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Regan Heath schrieb am Thu, 17 Mar 2005 20:07:08 +1300: > import std.stdio; > > class A > { > A opCatAssign(int[] arr) > { > foreach(int v; arr) > writefln(v); > > return this; > } > } > > class B > { > template opCatAssign(Type) > { > B opCatAssign(Type arr) > { > foreach(typeof(arr[0]) v; arr) > writefln(v); > > return this; > } > } > mixin opCatAssign!(int[]); > } > > void main() > { > static int[] arr = [0,1,2]; > A a = new A(); > B b = new B(); > > a ~= arr; > b ~= arr; //Error: Can only concatenate arrays > } > > Regan Added to DStress as http://dstress.kuehne.cn/run/opCatAssign_06.d http://dstress.kuehne.cn/run/opCatAssign_07.d http://dstress.kuehne.cn/run/opCatAssign_08.d Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFCQHdK3w+/yD4P9tIRAnm7AJwNGdsRxiHuuCyn48tGC2Wsji4ZxQCePopw EwW72e8kRRTbPEtl52evVPk= =9E2d -----END PGP SIGNATURE----- |
Copyright © 1999-2021 by the D Language Foundation