How do you overload opEquals?

Andrea Fontana nospam at example.com
Tue Nov 19 15:58:19 PST 2013


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 inheritance? If yes, use a 
> class, if no, struct is usually better, since it is lighter 
> weight and generally more flexible.

And, of course, struct are value type, class are reference type.
So, for example:

int i = 0;
while(++i < 10000000)
{
   S a; // if S is a class S a = new S;
   a.i = 10;
}

it's really faster if S is a struct


More information about the Digitalmars-d-learn mailing list