digitalmars.D.learn - Strong size_t
- Kagamin (3/3) Nov 26 2011 Tried to create a stronger version of size_t which will not interoperate...
- =?utf-8?Q?Simen_Kj=C3=A6r=C3=A5s?= (9/15) Nov 26 2011 Have you tried to overload opEquals and opCmp for ints? That seems to
- Kagamin (4/24) Nov 26 2011 It writes
- Steven Schveighoffer (6/32) Nov 26 2011 t =
Tried to create a stronger version of size_t which will not interoperate with int and long http://codepad.org/47OB3nJi But for some reason can't compare struct to int using opEquals and opCmp. How to fix it? And should it? One can write `v==intp(42)` or `v<intp(43)`.
Nov 26 2011
On Sat, 26 Nov 2011 17:22:58 +0100, Kagamin <spam here.lot> wrote:Tried to create a stronger version of size_t which will not interoperate with int and long http://codepad.org/47OB3nJi But for some reason can't compare struct to int using opEquals and opCmp. How to fix it? And should it? One can write `v==intp(42)` or `v<intp(43)`.Have you tried to overload opEquals and opCmp for ints? That seems to work just fine for me: bool opEquals(int v) const { return value == v; } int opCmp(int v) const { return value>v?1:value<v?-1:0; } Just add those to the intp struct.
Nov 26 2011
Simen Kjærås Wrote:On Sat, 26 Nov 2011 17:22:58 +0100, Kagamin <spam here.lot> wrote:It writes Error: function strongintp.intp.opEquals type signature should be const bool(ref const(intp)) not const bool(ref const const(short) v) Hmm... may be my compiler version is old and this was fixed...Tried to create a stronger version of size_t which will not interoperate with int and long http://codepad.org/47OB3nJi But for some reason can't compare struct to int using opEquals and opCmp. How to fix it? And should it? One can write `v==intp(42)` or `v<intp(43)`.Have you tried to overload opEquals and opCmp for ints? That seems to work just fine for me: bool opEquals(int v) const { return value == v; } int opCmp(int v) const { return value>v?1:value<v?-1:0; } Just add those to the intp struct.
Nov 26 2011
On Sat, 26 Nov 2011 11:45:26 -0500, Kagamin <spam here.lot> wrote:Simen Kj=C3=83=C2=A6r=C3=83=C2=A5s Wrote:On Sat, 26 Nov 2011 17:22:58 +0100, Kagamin <spam here.lot> wrote:Tried to create a stronger version of size_t which will not =` orinteroperatewith int and long http://codepad.org/47OB3nJi But for some reason can't compare struct to int using opEquals and opCmp. How to fix it? And should it? One can write `v=3D=3Dintp(42)=`v<intp(43)`.Have you tried to overload opEquals and opCmp for ints? That seems to=t =work just fine for me: bool opEquals(int v) const { return value =3D=3D v; } int opCmp(int v) const { return value>v?1:value<v?-1:0; } Just add those to the intp struct.It writes Error: function strongintp.intp.opEquals type signature should be cons=bool(ref const(intp)) not const bool(ref const const(short) v) Hmm... may be my compiler version is old and this was fixed...According to bugzilla, yes. http://d.puremagic.com/issues/show_bug.cgi?id=3D3659 -Steve
Nov 26 2011