comp.lang.ada
 help / color / mirror / Atom feed
From: Richard Riehle <richard@adaworks.com>
Subject: Re: proposal for new assignment operators
Date: Sun, 13 Jul 2003 18:39:27 -0700
Date: 2003-07-14T01:36:07+00:00	[thread overview]
Message-ID: <3F1209CF.C3907A61@adaworks.com> (raw)
In-Reply-To: 1ec946d1.0307070736.2eb5e820@posting.google.com

Matthew Heaney wrote:

> Richard Riehle <richard@adaworks.com> wrote in message news:<3F038B77.2F2E41B7@adaworks.com>...
> >
> > One reason for the peculiarity is that Ada, unlike C++, has limited
> > types.   For limited types, assignment is never possible.  Therefore,
> > overloading assignment is not possible.   Limited types are used for
> > most container classes.
>
> The statement that C++ doesn't have limited types is false.  To make a
> limited type in C++, you simply have to declare the assignment
> operator and copy constructor as private, and not define them:
>
> class Limited_Type is
> public:
>    void f();
> private:
>    Limited_Type& operator=(const Limited_Type&);
>    Limited_Type(const Limited_Type&);
> };

Limited types are not defined as part of the C++ standard.  One can, of
course, do as you  have with your example.   I rather doubt it is as common
as one would find in Ada.

> Also, most container types are not limited, because containers that
> are limited are hard to compose.  (It should be easy to instantiate a
> container type using another container type as the element type.)

Container types, perhaps not those you have created, are often designed
as limited types.   There are different points-of-view on this.   I recall
a PhD dissertation from OSU on this subject where the dissertation
recommended that all types for a container be limited, even the generic
formal parameters.

> The reason you need non-limited types is for composition, not for
> assignment (which has dubious value for a container).  There are many
> ways to copy a container without using the assignment operator.

Of course, the idiom for composing with a limited type involves a generic
formal access type parameter.  Recall the wonderful quote from Maurice
Wilkes relative to this issue.

> Also, the assignment operator only allows you to copy from the same
> type, but it's often the case that the source or target of the
> assignment is some other kind of container (e.g. an array).

Exactly.  This is one reason for not providing assignment over a limited
type.   Instead, we typically create a copy procedure and declare the
name of that copy procedure as specifically as possible.

> > It is rare that one even needs to override the assignment operator
> > on a non-limited type.   There is a distinction here that will not
> > be immediately obvious to the C++ programmer.
>
> You almost always need to override the assignment operator for a
> non-limited type, if the type allocates internal storage from a pool.

True when using indirection in your design. Also true for nearly
any composite type (where the partial definition is private).  Not true
when the full definition is not composite.

There is certainly overlap in the concerns of the Ada and C++ programmer.
I think the Ada programmer has an easier time with this than the C++
programmer.

Richard Riehle







  reply	other threads:[~2003-07-14  1:39 UTC|newest]

Thread overview: 69+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-06-25  6:23 proposal for new assignment operators Russ
2003-06-25  8:49 ` Preben Randhol
2003-06-25 10:28 ` Dmitry A. Kazakov
2003-06-25 10:36   ` Lutz Donnerhacke
2003-06-25 17:49     ` Dmitry A. Kazakov
2003-06-26 10:37       ` Lutz Donnerhacke
2003-06-27  8:15         ` Dmitry A. Kazakov
2003-06-27 14:21           ` Hyman Rosen
2003-06-25 19:17   ` Russ
2003-06-25 10:39 ` Larry Kilgallen
2003-06-25 12:06   ` Preben Randhol
2003-06-25 13:40     ` Peter Hermann
2003-06-25 22:12     ` Georg Bauhaus
2003-06-26  8:03       ` Preben Randhol
2003-06-26  8:25         ` Vinzent Hoefler
2003-06-26 15:02       ` Stephen Leake
2003-06-26 17:54         ` Georg Bauhaus
2003-06-26 18:32           ` Stephen Leake
2003-06-27 13:21             ` Georg Bauhaus
2003-06-26 16:32       ` Preben Randhol
2003-06-26 17:41         ` Georg Bauhaus
2003-06-26 17:58           ` Preben Randhol
2003-06-26  2:36     ` Steve
2003-06-26  2:33   ` Russ
2003-06-26 23:02     ` John R. Strohm
2003-06-25 14:07 ` Frank J. Lhota
2003-06-25 16:27   ` Warren W. Gay VE3WWG
2003-06-26  3:09     ` Russ
2003-06-26  6:27       ` Vinzent Hoefler
2003-06-26 10:49       ` Larry Kilgallen
2003-06-26 18:08         ` Russ
2003-06-26 18:19           ` Preben Randhol
2003-06-26 18:45           ` Larry Kilgallen
2003-07-02 15:57             ` Kevin Cline
2003-07-02 17:10               ` tmoran
2003-07-02 18:27                 ` Hyman Rosen
2003-07-02 20:20                   ` tmoran
2003-07-03  1:48               ` Richard Riehle
2003-07-03  3:07                 ` Hyman Rosen
2003-07-03  5:12                   ` Randy Brukardt
2003-07-03 13:03                     ` Hyman Rosen
2003-07-03 14:46                   ` Stephen Leake
2003-07-04  1:17                   ` James Rogers
2003-07-07  4:29                     ` Hyman Rosen
2003-07-08  1:10                       ` James Rogers
2003-07-08 13:59                         ` Hyman Rosen
2003-07-09  0:12                           ` James Rogers
2003-07-09  3:00                             ` Hyman Rosen
2003-07-07 15:36                 ` Matthew Heaney
2003-07-14  1:39                   ` Richard Riehle [this message]
2003-07-14  2:54                     ` Hyman Rosen
2003-07-16  3:14                       ` Richard Riehle
2003-06-27 13:34       ` Georg Bauhaus
2003-06-27 23:12         ` Russ
2003-06-27 23:21           ` Larry Kilgallen
2003-06-28 18:51             ` Russ
2003-06-27 18:02       ` Warren W. Gay VE3WWG
2003-06-28  3:50         ` Russ
2003-06-30 15:58           ` Warren W. Gay VE3WWG
2003-06-25 19:44 ` Bill Findlay
2003-06-26  2:06   ` Russ
2003-06-26  2:33     ` Bill Findlay
2003-06-26  5:54     ` Karel Miklav
2003-06-26 12:17     ` Georg Bauhaus
2003-06-26 12:52     ` Joseph Dalton
2003-06-26 18:11     ` Frank J. Lhota
  -- strict thread matches above, loose matches on Subject: below --
2003-06-27  5:35 christoph.grein
2003-06-27  9:57 ` Preben Randhol
2003-06-27 14:11 ` Georg Bauhaus
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox