In D it's not possible to make opCast operators implicit.
Therefore I see no way of making "transparent wrappers"; like
structs which could be used as a drop-in replacement for plain
old data types.
E.g if I wanted to make a SafeInt struct, that behaves otherwise
just like an int, but when operat
"Tommi" , dans le message (digitalmars.D:174314), a écrit :
> In D it's not possible to make opCast operators implicit.
> Therefore I see no way of making "transparent wrappers"; like
> structs which could be used as a drop-in replacement for plain
> old data types.
>
> E.g if I wanted to make a S
On Mon, 06 Aug 2012 15:29:47 +0200, Tommi wrote:
If you use alias this to _reveal_
the internal int value of SafeInt, then that int value's default
operators are used, and thus no overflow checking.
No.
--
Simen
E.g if I wanted to make a SafeInt struct, that behaves otherwise
just like an int, but when operators like +=, *=, ++, -- etc are
used with it, my custom SafeInt operators would check that
there's no integer overflow.
If you use alias this to _reveal_
the internal int value of SafeInt, then tha
On Monday, 6 August 2012 at 13:59:30 UTC, jerro wrote:
Wouldn't you have the exact same problem with implicit casts in
C++? If you want to use custom operators, you should just
define those, same as you would in C++. You can even implement
just some operators and use alias this for functionalit
On 08/06/12 15:29, Tommi wrote:
> In D it's not possible to make opCast operators implicit.
> Therefore I see no way of making "transparent wrappers"; like
> structs which could be used as a drop-in replacement for plain
> old data types.
>
> E.g if I wanted to make a SafeInt struct, that behaves
On 08/06/2012 08:08 AM, Artur Skawina wrote:
> There's sort-of limited support for implicit-casts - 'alias this'
> with a getter. That does not force exposure of the internal
> representation, but has other problems. The main one is of course
> that there can only be one 'alias this'.
Luckily, i