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=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,69b3e9746c62ec93 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.224.189.16 with SMTP id dc16mr11522357qab.0.1351358245275; Sat, 27 Oct 2012 10:17:25 -0700 (PDT) Received: by 10.52.97.101 with SMTP id dz5mr5097747vdb.2.1351358245252; Sat, 27 Oct 2012 10:17:25 -0700 (PDT) Path: r17ni73086299qap.0!nntp.google.com!e17no820767qar.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sat, 27 Oct 2012 10:17:25 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=91.7.92.202; posting-account=rmHyLAoAAADSQmMWJF0a_815Fdd96RDf NNTP-Posting-Host: 91.7.92.202 References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Conditional holder for a type with unknown discriminant From: AdaMagica Injection-Date: Sat, 27 Oct 2012 17:17:25 +0000 Content-Type: text/plain; charset=ISO-8859-1 Date: 2012-10-27T10:17:25-07:00 List-Id: Can't see why this shouldn't do the trick: package Owl_Holder is new Ada.Containers.Indefinite_Holders (T); use Owl_Holder; type R (Has_Item: Boolean) is record case Has_Item is when False => null; when True => I: Holder; end case; end record; Y: R := F (...); case Y.Has_Item is when False => null; -- Do nothing when True => P (Y.I.Element); -- Do whatever you want P (Element (Y.I); -- ditto P (Y.I.Reference); -- ditto using Ada 2012 reference type Y.I.Reference := New_Item; -- via reference type or Y.I.Replace_Element (New_Item); -- in traditional way end case; (Haven't compiled, but you get the idea:-)