From: mheaney@on2.com (Matthew Heaney)
Subject: Re: Clueless :)
Date: 18 Mar 2003 12:42:12 -0800
Date: 2003-03-18T20:42:13+00:00 [thread overview]
Message-ID: <1ec946d1.0303181242.1ddd372a@posting.google.com> (raw)
In-Reply-To: qHEda.2435$wK6.104835@news.siol.net
Karel Miklav <karel@inetis.spppambait.com> wrote in message news:<qHEda.2435$wK6.104835@news.siol.net>...
> Learning Ada I'm playing with container libraries and there are some
> things puzzling me. If I initialize a generic container with an abstract
> data type, this container will copy the whole ADT through and forth on
> every assignment and alike. Isn't this an overkill?
What do you mean by "copy the whole ADT" during assignment. Types
don't get copied --only objects do-- so your question doesn't make any
sense as written.
> As I understand he gets in an iterator to increase, but he throws it
> away and creates another one. Is it so cheap or am I missunderstanding
> something about Ada compilers or something?
You're constructing a new iterator object from an existing iterator
object. Sort of like the function:
class iterator {
public:
iterator succ() const;
//..
};
For example:
iterator i;
//...
i = i.succ();
The reason it's written this way in Ada is because scalar types have a
built-in function that already does that:
I : Integer;
--...
I := Integer'Succ (I);
John was just being consistent with the rest of the language. The
Charles container library (modelled on the C++ STL) is implemented
similarly:
http://home.earthlink.net/~matthewjheaney/charles/
> And one more question about the concept supported by keywords bounded,
> unbounded, dynamic, fixed-length etc. Like first I must admit I don't
> get it; why is there a need for this in Ada, when in tens of other
> languages I've seen there is not?
Because you don't have "bounded" forms in C++; that is, an array
declared on the stack whose size is dynamic, i.e.
void op(int n)
{
char str[n]; //not std c++
//...
You can do this in Ada, in C99, and in g++. For example:
procedure Op (N : Natural) is
S : String (1 .. N);
begin
--...
You typically need a "bounded" form in order to declare a stack-based
container, whose maximum number of items ("size") isn't know until
run-time:
procedure Op (Size : Natural) is
V : List_Subtype (Size); --no dynamic allocation
begin
> And why there are bounded, unbounded
> and dynamic versions of Booch components but no polymorphic?
Can't you just instantiate the container using an access type that
designates T'Class?
next prev parent reply other threads:[~2003-03-18 20:42 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-03-18 12:55 Clueless :) Karel Miklav
2003-03-18 16:37 ` Martin Krischik
2003-03-20 21:00 ` Simon Wright
2003-03-21 7:39 ` Karel Miklav
2003-03-21 8:34 ` Karel Miklav
2003-03-21 9:26 ` Karel Miklav
2003-03-21 18:01 ` Simon Wright
2003-03-18 20:42 ` Matthew Heaney [this message]
2003-03-19 6:43 ` Karel Miklav
2003-03-19 2:21 ` Jeffrey Carter
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox