Pointers or copies?

Frits van Bommel fvbommel at REMwOVExCAPSs.nl
Wed Dec 20 15:12:28 PST 2006


Orgoton wrote:
> And when I want to remove the reference? Something like
> 
> void remove(in object target)
> the_for:
> for (i=0; i<queue.length; i++)
> {
> if target==queue[i]
> {
> queue[i]=queue[$-1];
> queue.length-=1;
> break the_for;
> }
> }
> 
> the compare will work fine, right? I mean, in C++ it would just compare a 4 byte
> integer, how much data will D compare? hopefully, not he full object data ... ... ...

The compare will call opEquals, which will compare addresses by default. 
(Assuming the contents are class instances, not structs. Structs compare 
their contents by default)

Unfortunately, decreasing the queue length will have to be done like this:
	queue.length = queue.length - 1;
or:
	queue = queue[0 .. $-1];
because .length is a property, and as such op-assignments won't work, 
only direct assignment.



More information about the Digitalmars-d mailing list