Thread overview
painting arrays over arrays
Aug 17, 2005
BCS
Aug 17, 2005
Derek Parnell
Aug 17, 2005
Derek Parnell
August 17, 2005
Quite some time ago, I posted in one of these forums looking for a fast way to
“paint” a dynamic array of one type (int[5][] for example) over a dynamic array
of another type (int[]) several allocate-and-copy solutions were suggested, all
to slow, to clunky, etc. I found a good solution (see below) what I’m wondering
is were you all just being polite and not pointing out what a dumb-#$%@ I was
being or I did we all manage to not notice this one?

// take an input of type F[] and return an output of type T[] that overlays the input

template paint(T, F)
{
T[] paint(F[] data)
{
return (cast(T*)data.ptr)[0 .. data.length*F.sizeof/T.sizeof];
}
}


August 17, 2005
On Wed, 17 Aug 2005 20:05:43 +0000 (UTC), BCS wrote:

> Quite some time ago, I posted in one of these forums looking for a fast way to
> “paint” a dynamic array of one type (int[5][] for example) over a dynamic array
> of another type (int[]) several allocate-and-copy solutions were suggested, all
> to slow, to clunky, etc. I found a good solution (see below) what I’m wondering
> is were you all just being polite and not pointing out what a dumb-#$%@ I was
> being or I did we all manage to not notice this one?
> 
> // take an input of type F[] and return an output of type T[] that overlays the input
> 
> template paint(T, F)
> {
> T[] paint(F[] data)
> {
> return (cast(T*)data.ptr)[0 .. data.length*F.sizeof/T.sizeof];
> }
> }

No. That's basically what a few people said you needed to do.

-- 
Derek Parnell
Melbourne, Australia
18/08/2005 7:08:39 AM
August 17, 2005
On Thu, 18 Aug 2005 07:09:30 +1000, Derek Parnell wrote:

> On Wed, 17 Aug 2005 20:05:43 +0000 (UTC), BCS wrote:
> 
>> Quite some time ago, I posted in one of these forums looking for a fast way to
>> “paint” a dynamic array of one type (int[5][] for example) over a dynamic array
>> of another type (int[]) several allocate-and-copy solutions were suggested, all
>> to slow, to clunky, etc. I found a good solution (see below) what I’m wondering
>> is were you all just being polite and not pointing out what a dumb-#$%@ I was
>> being or I did we all manage to not notice this one?
>> 
>> // take an input of type F[] and return an output of type T[] that overlays the input
>> 
>> template paint(T, F)
>> {
>> T[] paint(F[] data)
>> {
>> return (cast(T*)data.ptr)[0 .. data.length*F.sizeof/T.sizeof];
>> }
>> }
> 
> No. That's basically what a few people said you needed to do.

Sorry, I tell a lie. Your solution is much better than the ones provided earlier.

-- 
Derek Parnell
Melbourne, Australia
18/08/2005 7:21:23 AM