From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,9eef6c480abeecf8 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!newsread.com!news-xfer.newsread.com!nntp.abs.net!attws2!att542!ip.att.net!newsfeed3.global.lmco.com!svlnews.lmms.lmco.com!not-for-mail From: "REH" Newsgroups: comp.lang.ada Subject: Re: Dynamic array allocation and STL equivalents? Date: Fri, 11 Feb 2005 12:47:48 -0500 Organization: Earth Message-ID: References: <1108127216.221977.60830@o13g2000cwo.googlegroups.com> <13r5d1sfsg55d$.1u0p9rdnt3zcy.dlg@40tude.net> NNTP-Posting-Host: 158.187.64.144 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1437 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 Xref: g2news1.google.com comp.lang.ada:8250 Date: 2005-02-11T12:47:48-05:00 List-Id: "Dmitry A. Kazakov" 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 operator, (I i, J j) {return std::make_pair(size_t(i), size_t(j));} inline size_t operator, (const std::pair& 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.