User-defined "opIs"

via Digitalmars-d digitalmars-d at puremagic.com
Sun Sep 28 07:43:03 PDT 2014


On Sunday, 28 September 2014 at 14:27:56 UTC, Marco Leise wrote:
> Am Sun, 28 Sep 2014 10:44:47 +0000
> schrieb "Marc Schütz" <schuetzm at gmx.net>:
>
>> On Saturday, 27 September 2014 at 11:38:51 UTC, Marco Leise 
>> wrote:
>> >   A byte for byte comparison of both operands is performed.
>> >   For reference types this is the reference itself.
>> 
>> Maybe allow this only for types that somehow implicitly 
>> convert to each other, i.e. via alias this?
>
> That sounds like a messy rule set on top of the original when
> alias this does not represent all of the type. You have a
> size_t and a struct with a pointer that aliases itself to some
> size_t that can be retrieved through that pointer.
> The alias this will make it implicitly convert to size_t and
> the byte for byte comparison will happily compare two equally
> sized varibles (size_t and pointer).
> So how narrow would the rule have to be defined before it
> reads:
>
>   If you compare with a struct that consists only of one member
>   that the struct aliases itself with, a variable of the type
>   of that member will be compared byte for byte with the
>   struct.

Yeah, it wasn't a good idea. Somehow it felt strange to throw all 
type safety out of the window, but on the other hand, bit-level 
comparison is the purpose of `is`, which isn't typesafe to begin 
with.


More information about the Digitalmars-d mailing list