Re: Prevent self-comparison without taking the address

2024-07-26 Thread Dom DiSc via Digitalmars-d-learn
On Thursday, 25 July 2024 at 15:40:29 UTC, Nick Treleaven wrote: On Thursday, 25 July 2024 at 15:06:35 UTC, IchorDev wrote: I think your function most likely has a safe interface, so it can be marked as `@trusted` as-per [the spec](https://dlang.org/spec/function.html#safe-interfaces). Just

Re: Prevent self-comparison without taking the address

2024-07-25 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, July 25, 2024 4:50:04 AM MDT Dom DiSc via Digitalmars-d-learn wrote: > I have copied some source from C++, where the following pattern > is common (operator== already renamed): > > ```d > @safe: > struct S > { > bool opEquals(const ref S x) const > { >if(==) return

Re: Prevent self-comparison without taking the address

2024-07-25 Thread Nick Treleaven via Digitalmars-d-learn
On Thursday, 25 July 2024 at 15:06:35 UTC, IchorDev wrote: I think your function most likely has a safe interface, so it can be marked as `@trusted` as-per [the spec](https://dlang.org/spec/function.html#safe-interfaces). Just to mention that with -dip1000, taking the address of variables is

Re: Prevent self-comparison without taking the address

2024-07-25 Thread IchorDev via Digitalmars-d-learn
On Thursday, 25 July 2024 at 14:05:50 UTC, Dom DiSc wrote: As he said: no. It's only true for @safe: No they did not, they specifically said that my assertion holds true for all other [function attributes](https://dlang.org/spec/attribute.html#function-attributes). This does not tell me

Re: Prevent self-comparison without taking the address

2024-07-25 Thread Dom DiSc via Digitalmars-d-learn
On Thursday, 25 July 2024 at 13:20:59 UTC, IchorDev wrote: On Thursday, 25 July 2024 at 13:01:53 UTC, Dennis wrote: That's true for the other function attributes, but `@safe:` actually does penetrate scopes The spec doesn’t mention this at all! Is this the case for any other

Re: Prevent self-comparison without taking the address

2024-07-25 Thread IchorDev via Digitalmars-d-learn
On Thursday, 25 July 2024 at 13:01:53 UTC, Dennis wrote: That's true for the other function attributes, but `@safe:` actually does penetrate scopes The spec doesn’t mention this at all! Is this the case for any other `AttributeSpecifier` declarations?

Re: Prevent self-comparison without taking the address

2024-07-25 Thread Dennis via Digitalmars-d-learn
On Thursday, 25 July 2024 at 11:46:29 UTC, IchorDev wrote: Also just so you know, placing `@safe:` there will not affect the contents of `S`. It has to be inside the struct declaration to affect its contents. That's true for the other function attributes, but `@safe:` actually does penetrate

Re: Prevent self-comparison without taking the address

2024-07-25 Thread IchorDev via Digitalmars-d-learn
On Thursday, 25 July 2024 at 10:50:04 UTC, Dom DiSc wrote: ```d @safe: struct S{ ``` Also just so you know, placing `@safe:` there will not affect the contents of `S`. It has to be inside the struct declaration to affect its contents.

Re: Prevent self-comparison without taking the address

2024-07-25 Thread IchorDev via Digitalmars-d-learn
On Thursday, 25 July 2024 at 10:50:04 UTC, Dom DiSc wrote: Can I replace this pattern with ```(x is this)``` or are there some special cases where this doen't work? When a parameter is `ref` it is treated as a value type (i.e. it has value semantics), even though it is a reference; therefore

Prevent self-comparison without taking the address

2024-07-25 Thread Dom DiSc via Digitalmars-d-learn
I have copied some source from C++, where the following pattern is common (operator== already renamed): ```d @safe: struct S { bool opEquals(const ref S x) const { if(==) return true; ... } } ``` Can I replace this pattern with ```(x is this)``` or are there some special