From: "REH" <bogus@nowhere.net>
Subject: Re: Dynamic array allocation and STL equivalents?
Date: Fri, 11 Feb 2005 12:47:48 -0500
Date: 2005-02-11T12:47:48-05:00 [thread overview]
Message-ID: <cuir44$qrg2@cui1.lmms.lmco.com> (raw)
In-Reply-To: 13r5d1sfsg55d$.1u0p9rdnt3zcy.dlg@40tude.net
"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message
news:13r5d1sfsg55d$.1u0p9rdnt3zcy.dlg@40tude.net...
> On 11 Feb 2005 05:06:56 -0800, brian.b.mcguinness@lmco.com wrote:
> Index of a multi-dimensional array is a tuple. That won't work in C++ (you
> cannot override "," to support: A[i,j,k]). Neither works it in Ada.
>
Sure you can (though I don't avocate it). Off the top of my head:
use enumeration type and operator overloading of ",".
enum I {i_first = 0, i_max = 10};
enum J {j_first = 0, j_max = 10};
enum K {k_first = 0, k_max = 10};
const size_t size = sizeof(int);
inline std::pair<size_t, size_t> operator, (I i, J j) {return
std::make_pair(size_t(i), size_t(j));}
inline size_t operator, (const std::pair<size_t, size_t>& p, K k)
{
size_t i = p.first * k_max * j_max * size;
i += p.second * k_max * size;
i += k;
return i;
}
int* array = new int[i_max * j_max * k_max];
int* p = array[I(5), J(6), K(7)];
You can cleanup and "genericize" this more with templates. My math may be
off, but the concept is the same.
As I said, I wouldn't do it, but it is possible.
next prev parent reply other threads:[~2005-02-11 17:47 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-02-11 13:06 Dynamic array allocation and STL equivalents? brian.b.mcguinness
2005-02-11 13:43 ` Jeff C
2005-02-14 15:23 ` Marc A. Criley
2005-02-11 14:41 ` Dmitry A. Kazakov
2005-02-11 15:50 ` Adrien Plisson
2005-02-11 17:47 ` REH [this message]
2005-02-12 9:28 ` Dmitry A. Kazakov
2005-02-12 18:52 ` Robert A Duff
2005-02-11 17:24 ` Bobby D. Bryant
2005-02-12 0:06 ` Robert A Duff
2005-02-12 3:45 ` Bobby D. Bryant
2005-02-11 18:07 ` Matthew Heaney
2005-02-11 18:36 ` Martin Krischik
2005-02-11 19:35 ` brian.b.mcguinness
2005-02-12 1:04 ` Jeffrey Carter
2005-02-12 6:19 ` Bobby D. Bryant
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox