comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Dynamic array allocation and STL equivalents?
Date: Sat, 12 Feb 2005 10:28:20 +0100
Date: 2005-02-12T10:28:20+01:00	[thread overview]
Message-ID: <otmmmy3rsvvv.aedk4cjbs02u$.dlg@40tude.net> (raw)
In-Reply-To: cuir44$qrg2@cui1.lmms.lmco.com

On Fri, 11 Feb 2005 12:47:48 -0500, REH wrote:

> "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). 

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<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)];

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



  reply	other threads:[~2005-02-12  9:28 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
2005-02-12  9:28     ` Dmitry A. Kazakov [this message]
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