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=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.107.105.9 with SMTP id e9mr2139767ioc.87.1522553499744; Sat, 31 Mar 2018 20:31:39 -0700 (PDT) X-Received: by 2002:a9d:58c9:: with SMTP id s9-v6mr245588oth.0.1522553499651; Sat, 31 Mar 2018 20:31:39 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!paganini.bofh.team!weretis.net!feeder6.news.weretis.net!feeder.usenetexpress.com!feeder-in1.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!u184-v6no2636270ita.0!news-out.google.com!u64-v6ni3388itb.0!nntp.google.com!u184-v6no2636268ita.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sat, 31 Mar 2018 20:31:39 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=173.71.218.250; posting-account=QF6XPQoAAABce2NyPxxDAaKdAkN6RgAf NNTP-Posting-Host: 173.71.218.250 References: <6b8fb3ef-700f-4930-9a1e-5126d9482a26@googlegroups.com> <3d0554a2-95e8-4f8f-9fdf-1743d3f1dc18@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <452ef4be-7210-4aca-9c48-12be7f0e9b94@googlegroups.com> Subject: Re: limited agregate and limited components default initialization From: Jere Injection-Date: Sun, 01 Apr 2018 03:31:39 +0000 Content-Type: text/plain; charset="UTF-8" Xref: reader02.eternal-september.org comp.lang.ada:51272 Date: 2018-03-31T20:31:39-07:00 List-Id: On Saturday, March 31, 2018 at 11:14:49 PM UTC-4, Jere wrote: > On Saturday, March 31, 2018 at 10:07:20 PM UTC-4, Jean-Claude Rostaing wrote: > > type ITEM_ACCESS; > > type Item_Record is limited > > record > > Item: aliased Item_type; > > Next : Item_Access; > > Pred : Item_Access; > > end record; > > package Record_Pointers is new Pointers (Item_type => Item_Record); > > type Item_Access is new Record_Pointers.Smart_Pointers; > > Side note: I couldn't get this to compile because Next and Pred > are incomplete types (so they too cannot be used a variable types. > > The proper way to do it would be: > type Item_Record; > package Record_Pointers is new Pointers (Item_type => Item_Record); > type Item_Access is new Record_Pointers.Smart_Pointers; > > type Item_Record is limited > record > Item : aliased Item_type; > Next : Item_Access; > Pred : Item_Access; > end record; > > but your Pointers package will need an incomplete formal type for it to > work: > > generic > type Item_Type(<>); > package Pointers is > -- stuff > end Pointers; > > and that might cause you other problems, but if you want to use > your smart pointers in a self referential type, you'll need your > smart pointer generic to use incomplete types. Since you didn't supply a minimally compilable example, I made a quick one stubbing in the things you didn't specify. Hopefully this will help give some ideas on what I mean: procedure jdoodle is generic type Item_Type(<>); package Pointers is type Smart_Pointers is limited null record; end Pointers; generic type Item_Type is limited private; with function Make_Item return Item_Type; package Lists is type List_Type is limited private; type Item_Accessor (Item: not null access Item_type) is limited private with Implicit_Dereference => Item; -- added stub type List_Iterator is limited record Ref : access Item_Type; end record; function Get(Position: in List_Iterator) return Item_Accessor; private type Item_Record; package Record_Pointers is new Pointers (Item_type => Item_Record); type Item_Access is new Record_Pointers.Smart_Pointers; type Item_Record is limited record Item : aliased Item_type; Next : Item_Access; Pred : Item_Access; end record; -- Added stub function Set(value : Item_Record) return Item_Access is (others => <>); type Item_Accessor (Item: not null access Item_type) is limited record REF: ITEM_ACCESS := Set(Item_Record'(Make_Item, others => <>)); end record; function Get(Position: in List_Iterator) return Item_Accessor is (Item => Position.Ref, others => <>); type List_Type is limited record First: Item_Access; Last : Item_Access; Count : Natural := 1; end record; end lists; ----------------------------------------------------------- -- Testing package instantiation ----------------------------------------------------------- type Test is record value : Integer := 0; end record; function Make_Test return Test is (value => 10); package Test_Lists is new Lists(Item_Type => Test, Make_Item => Make_Test); begin null; end jdoodle;