Re: How do you overload opEquals?

2013-11-19 Thread Mike Parker
On 11/20/2013 5:59 AM, Dale Matthews wrote: class Vec3 { bool opEquals()(auto ref const Vec3 v) const You don't need to use 'ref' on parameters that are classes. Unlike C++, D classes are already reference types, not value types. More like Java. Structs, OTOH, are value types. With t

Re: How do you overload opEquals?

2013-11-19 Thread Adam D. Ruppe
On Tuesday, 19 November 2013 at 23:58:20 UTC, Andrea Fontana wrote: And, of course, struct are value type, class are reference type. Yeah, true in general, though it is possible to have a struct be very similar to a reference type. Consider: struct WrappedClass { Object obj; /* and wha

Re: How do you overload opEquals?

2013-11-19 Thread Andrea Fontana
On Tuesday, 19 November 2013 at 21:33:31 UTC, Adam D. Ruppe wrote: On Tuesday, 19 November 2013 at 21:25:47 UTC, Dale Matthews wrote: Adam, do you recommend using a struct instead of a class? Yes, I would use a struct instead of a class here. The key question to ask in D is: do you need inher

Re: How do you overload opEquals?

2013-11-19 Thread Adam D. Ruppe
On Tuesday, 19 November 2013 at 21:25:47 UTC, Dale Matthews wrote: Adam, do you recommend using a struct instead of a class? Yes, I would use a struct instead of a class here. The key question to ask in D is: do you need inheritance? If yes, use a class, if no, struct is usually better, since

Re: How do you overload opEquals?

2013-11-19 Thread Dale Matthews
On Tuesday, 19 November 2013 at 21:22:27 UTC, Adam D. Ruppe wrote: IGNORE ME, I am wrong here. I mixed up opEquals and opAssign in my head. Sorry! Will do :]

Re: How do you overload opEquals?

2013-11-19 Thread Dale Matthews
On Tuesday, 19 November 2013 at 21:10:57 UTC, Chris Nicholson-Sauls wrote: override bool opEquals (Object o) const { if ( auto v = cast( typeof( this ) ) o ) return x == v.x && y == v.y && z == v.z; return false; } You need: 1) 'override' in order to override

Re: How do you overload opEquals?

2013-11-19 Thread Adam D. Ruppe
On Tuesday, 19 November 2013 at 21:05:23 UTC, Adam D. Ruppe wrote: opEquals doesn't work on classes with class references. IGNORE ME, I am wrong here. I mixed up opEquals and opAssign in my head. Sorry!

Re: How do you overload opEquals?

2013-11-19 Thread Chris Nicholson-Sauls
On Tuesday, 19 November 2013 at 20:59:31 UTC, Dale Matthews wrote: I'm brand new to D and I'm taking on a project. In the midst, I've overloaded a whole load of operators for my Vec3 class. Most seem to be working (I haven't tested them all yet) but opEquals is refusing to be called. I've follo

Re: How do you overload opEquals?

2013-11-19 Thread Adam D. Ruppe
On Tuesday, 19 November 2013 at 20:59:31 UTC, Dale Matthews wrote: I feel like I'm missing something simple. opEquals doesn't work on classes with class references. It doesn't call a method with obj = other_obj, it just rebinds the reference. If you want full control over opEquals, it'll have

How do you overload opEquals?

2013-11-19 Thread Dale Matthews
I'm brand new to D and I'm taking on a project. In the midst, I've overloaded a whole load of operators for my Vec3 class. Most seem to be working (I haven't tested them all yet) but opEquals is refusing to be called. I've followed the guidelines here: http://dlang.org/operatoroverloading.html#