easier way?

Jason Spencer spencer8 at sbcglobal.net
Wed Aug 25 17:36:26 PDT 2010


== Quote from bearophile (bearophileHUGS at lycos.com)'s article
> Jason Spencer:
> > Is there a better way to lay this out?
> Is this good enough for you?

It's certainly better.  I'll have to look at how this plays with some
of my other usage, where dimensions come into play, but this is
definitely a step forward for me.

> >  - get the size easily without pointer tricks that are still
> > strictly speaking not safe without iterating over n-1 dimensions
> I don't see how they help here. What kind of pointer tricks?

Stupid stuff, that won't account for varying row sizes (which isn't
anything I need anyway.)  Things like (&array[$][$] -
&array[0][0])/sizeof(array[0][0]), properly cast, etc.

> >  - (as above) discriminate on array types passed 1-D, esp. at
> > compile time.  i.e. I can't make any template functions to work on
> > arrays of varying dimensions unless they're static arrays, which
> > doesn't really help.
> My example may help.

Yeah, maybe.  I guess the matrix thing will end up being what I really
need.  In that case, I'd probably template on the element type and the
size in each dimension, where latter dimensions are allowed to be of 0
size.  But to implement that struct/class, I still see it ending up as
allocating one memory chunk and indexing manually via pointers.  I can
never cast a dynamic array to a static array, so I can never write
templates for static types.  All sizes will still be dynamic.  So I'm
not sure a class wrapper would buy me that much.  Maybe I'm back to
your static dispatch trick...

Jason



More information about the Digitalmars-d-learn mailing list