comp.lang.ada
 help / color / mirror / Atom feed
From: Georg Bauhaus <rm.dash-bauhaus@futureapps.de>
Subject: Re: smart pointer dangerous (no -> operator)
Date: Fri, 16 Jan 2009 12:42:17 +0100
Date: 2009-01-16T12:42:17+01:00	[thread overview]
Message-ID: <49707299$0$32667$9b4e6d93@newsspool2.arcor-online.net> (raw)
In-Reply-To: <a8go9gb0a60q.wypnft0gfg98$.dlg@40tude.net>

Dmitry A. Kazakov schrieb:
> On Fri, 16 Jan 2009 11:04:57 +0100, Oliver Kowalke wrote:
> 
>> Ada doesn't support the dereference operator -> as C++.
>>
>> So Ada provides only two ways to access the managed object?

> Two major problems
> are:
> 
> 1. Lack of delegation in order to automate generation of wrappers like Foo.
> 2. Lack of MI, because one base type is required and used further extension
> of the target type becomes practically impossible.

Frequently overlooked, I think, Ada has nested scopes, useful
in many ways here. (Except, perhaps, if reuse is only be
perceived to be possible with flat library level compiled
brick stone, and not by reusing source code and some
programming...)

1 - Ownership of objects can be strictly confined in scopes.

2 - Types can be declared where they are needed. See 1.

3 - Finalization is performed when a scope ends.

These may not directly address the original question,
but why design a program around C++ imported hindrances,
if you will?

with Ada.Finalization, Ada.Text_IO;

procedure Scoped_Pointer is

   procedure Local is
      -- architectural unit

      type T is new Ada.Finalization.Controlled with
         record
            Data: Character;
         end record;

      overriding procedure Finalize(Object: in out T) is
      begin
         Ada.Text_IO.Put_Line("F!");
      end Finalize;

      procedure Next(Item: in out T) is
         -- may raise
      begin
         Item.Data := Character'Val
           (Natural'Succ(Character'Pos(Item.Data)));
      end Next;

      -- Pointer whose objects do not exist outside Local:
      type T_Ptr is access T;
      X: T_Ptr;

   begin  -- Local
      X := new T'(Ada.Finalization.Controlled with Data => '*');
      loop
         Next(X.all);  -- passed by reference; raises
      end loop;
   end Local;

begin
   -- Local.T does not exist
   Local;
   -- Local.T does not exist, neither does Local.X.all,
   -- as it has been finalized automatically.
end Scoped_Pointer;




  reply	other threads:[~2009-01-16 11:42 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-16 10:04 smart pointer dangerous (no -> operator) Oliver Kowalke
2009-01-16 11:09 ` Dmitry A. Kazakov
2009-01-16 11:42   ` Georg Bauhaus [this message]
2009-01-16 12:43     ` Dmitry A. Kazakov
2009-01-16 21:21     ` Maciej Sobczak
2009-01-17 19:07       ` Georg Bauhaus
2009-01-16 11:46   ` Oliver Kowalke
2009-01-16 12:45     ` Dmitry A. Kazakov
2009-01-17  0:43   ` Brian Drummond
2009-01-17  9:28     ` Dmitry A. Kazakov
2009-01-16 20:08 ` Tero Koskinen
2009-01-16 21:16   ` Maciej Sobczak
2009-01-18 12:21 ` Samuel Tardieu
replies disabled

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