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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no 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!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Dynamic array allocation and STL equivalents? Date: Sat, 12 Feb 2005 10:28:20 +0100 Organization: cbb software GmbH Message-ID: References: <1108127216.221977.60830@o13g2000cwo.googlegroups.com> <13r5d1sfsg55d$.1u0p9rdnt3zcy.dlg@40tude.net> Reply-To: mailbox@dmitry-kazakov.de Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: individual.net 5YqbKToS0qdbZL73itFQ5wnLXEfzf3NWSSjUg3rW8T+G8dbWc= User-Agent: 40tude_Dialog/2.0.14.1 Xref: g2news1.google.com comp.lang.ada:8274 Date: 2005-02-12T10:28:20+01:00 List-Id: On Fri, 11 Feb 2005 12:47:48 -0500, REH wrote: > "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). OK > 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)]; This is still static and also because there are explicit type specifications. Should we try class IndexTuple { public : IndexTuple (int); IndexTuple operator, (int); protected : // some unbounded index array implementation }; Then I'm not sure if any C++ compiler would be able to resolve "Array [1, 2]" to IndexTuple::operator, (IndexTuple::IndexTuple (1), 2) keeping "SomethingUnrelated (1, 2)" resolved to SomethingUnrelated (1, 2) to I have an impression that C++ resolution rules are strictly bottom-up, so it wouldn't work without explicit type specifications here and there. So in the end it would be even worse than my variant with Ada's aggregates. I would really like Ada 2010 to respond to these issues. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de