Re: how to make '==' safe for classes?

2018-10-28 Thread ikod via Digitalmars-d-learn
Thanks for excellent explanation! On Sunday, 28 October 2018 at 19:00:52 UTC, Jonathan M Davis wrote: Because Object predats @safe (and most attributes), it really isn't compatible with them. In fact, it predates const (since it's basically the same as it was in D1) and it's only possible

Re: how to make '==' safe for classes?

2018-10-28 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, October 28, 2018 12:56:10 PM MDT ikod via Digitalmars-d-learn wrote: > On Sunday, 28 October 2018 at 18:00:06 UTC, Stanislav Blinov > > wrote: > > On Sunday, 28 October 2018 at 12:38:12 UTC, ikod wrote: > >> and object.opEquals(a,b) do not inherits safety from class C > >> properties,

Re: how to make '==' safe for classes?

2018-10-28 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, October 28, 2018 6:38:12 AM MDT ikod via Digitalmars-d-learn wrote: > Hello > > How to make this code to compile? My goal is safe(not @trusted) > longFunction(). > > > --- > class C > { > override bool opEquals(Object o) const @safe > { > return true; > } > } >

Re: how to make '==' safe for classes?

2018-10-28 Thread ikod via Digitalmars-d-learn
On Sunday, 28 October 2018 at 18:00:06 UTC, Stanislav Blinov wrote: On Sunday, 28 October 2018 at 12:38:12 UTC, ikod wrote: and object.opEquals(a,b) do not inherits safety from class C properties, and also I can't override it. Yep. Since Object is the base class and it defines opEquals as:

Re: how to make '==' safe for classes?

2018-10-28 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, October 28, 2018 12:17:41 PM MDT Neia Neutuladh via Digitalmars- d-learn wrote: > On Sun, 28 Oct 2018 18:00:06 +, Stanislav Blinov wrote: > > On Sunday, 28 October 2018 at 12:38:12 UTC, ikod wrote: > >> and object.opEquals(a,b) do not inherits safety from class C > >> properties,

Re: how to make '==' safe for classes?

2018-10-28 Thread Neia Neutuladh via Digitalmars-d-learn
On Sun, 28 Oct 2018 18:00:06 +, Stanislav Blinov wrote: > On Sunday, 28 October 2018 at 12:38:12 UTC, ikod wrote: > >> and object.opEquals(a,b) do not inherits safety from class C >> properties, and also I can't override it. > > Yep. Since Object is the base class and it defines opEquals

Re: how to make '==' safe for classes?

2018-10-28 Thread Stanislav Blinov via Digitalmars-d-learn
On Sunday, 28 October 2018 at 12:38:12 UTC, ikod wrote: and object.opEquals(a,b) do not inherits safety from class C properties, and also I can't override it. Yep. Since Object is the base class and it defines opEquals as: ``` bool opEquals(Object); ``` the compiler rewrites `a == b` as

how to make '==' safe for classes?

2018-10-28 Thread ikod via Digitalmars-d-learn
Hello How to make this code to compile? My goal is safe(not @trusted) longFunction(). --- class C { override bool opEquals(Object o) const @safe { return true; } } bool longFunction(C a, C b) @safe { return a==b; } void main() { } --- As far as I understand the