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,1888e8caa20a2f2d X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!news2.volia.net!news.germany.com!news.belwue.de!newsfeed.arcor.de!news.arcor.de!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Controlled types and exception safety Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.14.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <8sKdnXNeIZMxIg3eRVn-ig@comcast.com> Date: Tue, 6 Dec 2005 10:50:22 +0100 Message-ID: <3trncoj4t0va.19bs46zhm4xbe.dlg@40tude.net> NNTP-Posting-Date: 06 Dec 2005 10:50:26 MET NNTP-Posting-Host: 0e295d25.newsread4.arcor-online.net X-Trace: DXC=?be]ob7fk[X>K]\3>m]<[U:ejgIfPPldTjW\KbG]kaMXFYk:AnJB[C]C17_l3Fi;HU[6LHn;2LCV^7enW;^6ZC`T<=9bOTW=MN^ X-Complaints-To: usenet-abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:6745 Date: 2005-12-06T10:50:26+01:00 List-Id: On Tue, 06 Dec 2005 10:00:39 +0100, Maciej Sobczak wrote: > This brings me to the next problem. Let's say that I provide a separate > procedure Duplicate or Copy or Assign or whatever with the > commit-or-rollback guarantees for some type (like Stack). Now, some of > the types in my program will have ":=" for assignment, and some others > will have the Copy procedure, but not ":=". > I want to create a generic container or some other component that will > copy things around internally. It has to use ":=" for some types (like > Integer) and Copy for others (like Stack). > In C++ I solve this problem (aside the fact that there is no problem in > the first place) with template type traits or some other application of > template specializations. > What about Ada? generic type Object is limited private; with procedure Deep_Copy (Left : in out Object; Right : Object) is <>; package Container is ... end Container; ------------------------------- with Container; generic type Object is private; package Specialized_Container is procedure Deep_Copy (Left : in out Object; Right : Object); pragma Inline (Deep_Copy); package Copying_By_Assignment is new Container (Object); end Specialized_Container; ------------------------------- package body Specialized_Container is procedure Deep_Copy (Left : in out Object; Right Object) is begin Left := Right; end Deep_Copy; end Specialized_Container; Note also that your example is not much realistic. Transaction model is expensive. One usually does not compose transactions. This means that components of a container will be copied destructively, *after* necessary memory allocation. Only the upper level will take care of a possibility to roll things back. Thus it makes much sense to distinguish light-weight ":=" (which can't fail) and heavy-weight "Copy". The container itself could be a red-black tree, which supports roll-backs after mutations. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de