comp.lang.ada
 help / color / mirror / Atom feed
From: AdaMagica <christ-usch.grein@t-online.de>
Subject: Re: Conditional holder for a type with unknown discriminant
Date: Sat, 27 Oct 2012 10:17:25 -0700 (PDT)
Date: 2012-10-27T10:17:25-07:00	[thread overview]
Message-ID: <a1461547-5e69-4936-bde9-e91724cbbe4b@googlegroups.com> (raw)
In-Reply-To: <op.wmtgu2dfule2fv@cardamome>

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:-)




  parent reply	other threads:[~2012-10-27 17:17 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-27  2:50 Conditional holder for a type with unknown discriminant Yannick Duchêne (Hibou57)
2012-10-27  9:15 ` AdaMagica
2012-10-27 12:03   ` Yannick Duchêne (Hibou57)
2012-10-27 17:17 ` AdaMagica [this message]
2012-10-27 19:14 ` gautier_niouzes
2012-10-29  7:22   ` Yannick Duchêne (Hibou57)
replies disabled

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