comp.lang.ada
 help / color / mirror / Atom feed
From: "Jeffrey R. Carter" <spam.jrcarter.not@spam.not.acm.org>
Subject: Re: controlled types and point of instanciation
Date: Fri, 16 Mar 2018 22:44:07 +0100
Date: 2018-03-16T22:44:07+01:00	[thread overview]
Message-ID: <p8hdr8$pr7$1@dont-email.me> (raw)
In-Reply-To: <14ed4d30-f4ea-4a5e-9c32-ab689df7a1d5@googlegroups.com>

On 03/16/2018 07:06 PM, Mehdi Saada wrote:
> 
> function Pointer (Value : Access_Type) return Pointer_Type is
>      Object : Pointer_Type;
> begin
>      if Object.Pointer /= null then
>         Delete_Item (Object.Pointer.Value);
>      else
>         Object.Pointer := new Reference_Counted_Object;
>      end if;
>      Object.Pointer.all := (Value => Value, Count => 1);
>      return Object;
> end Pointer;
> 
> type Pointer_Type is new Ada.Finalization.Controlled with
> record
>       Pointer : Reference_Counted_Pointer;
> end record;
> and Pointer is a banal access type.
> type Reference_Counted_Pointer is access Reference_Counted_Object;

Oject.Pointer will always be null, so this seems unnecessarily complex. I'd 
probably just write

return new Reference_Counted_Object'(Pointer => (Value => Value, Count => 1) );

-- 
Jeff Carter
"Blessed are they who convert their neighbors'
oxen, for they shall inhibit their girth."
Monty Python's Life of Brian
83


  reply	other threads:[~2018-03-16 21:44 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-16 14:39 controlled types and point of instanciation Mehdi Saada
2018-03-16 16:31 ` J-P. Rosen
2018-03-16 17:14   ` Mehdi Saada
2018-03-16 18:06 ` Mehdi Saada
2018-03-16 21:44   ` Jeffrey R. Carter [this message]
2018-03-17  0:54 ` Mehdi Saada
replies disabled

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