There must be a better way

Unknown W. Brackets unknown at
Wed Aug 2 00:27:56 PDT 2006

I'm not clear on where your going, but I like to keep things simpler and 
thus more maintainable.  Instead of:


I would probably prefer...

whatever_t getWrapped(whatever_t[][] array, int x, int y, int var)
	return array[wrap(something[var].maxX, x)][wrap(something[var].maxY, y)];

Then you'd do:

array.getWrapped(currentX, currentY, var);

Which would seem much easier, and should be optimized out the same with 
inlining.  But this might not be practical depending on what "something" 
is (I'm guessing here it's a lookup or something.)

Also, fwiw, I use inout all the time.  I think there are specific design 
patterns and code paths with which it makes complete sense.  Example:

// Attempt to bring item to the top/head of the linked list.
if (!bringToTop(linked_list, item))
	writefln("Uh oh, %s was not found!", item.toString());

I don't think it's ambiguous that linked_list might be modified.  Just 
my opinion.  I might prefer "linked_list.bringToTop(item)" if it made 
sense, though (since that's even harder to misunderstand.)


> Thanks for the maths :)
> The maximum are not constant and writing out the place they live would yield 
> to something like:
> array[wrap(something[var].maxX,currentX)][wrap(something[var].maxY,currentY)];
> So the int was a bit of a hack... sorry :)
> About the inout:
> How would you do something like this?
> bool something(inout structure struc ,int var){
>   for (int i=0; i <[].length; i++){
>     if([i].count==0){
>       return true;
>     }
>   }
>   return false;
> }

More information about the Digitalmars-d-learn mailing list