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: 103376,dad94612ff745427 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news3.google.com!news2.volia.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: "Alex R. Mosteo" Newsgroups: comp.lang.ada Subject: Avoiding use Ada.Tags (was Re: Instantiating private types with discriminants?) Date: Tue, 09 May 2006 17:53:47 +0200 Message-ID: <4cbs83F14gl9qU1@individual.net> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit X-Trace: individual.net 9gPLxi65JmMMKzjuoRQCYwzaIvkjla7QgZhUQrnelpO63M++M= User-Agent: KNode/0.10.2 Xref: g2news2.google.com comp.lang.ada:4159 Date: 2006-05-09T17:53:47+02:00 List-Id: rick H wrote: > (...) > I'm trying to query the tag of a record, which I can do quite nicely, > provided I both "with Ada.Tags" and "use Ada.Tags". Just for the sake > of it, I tried to remove the "use Ada.Tags" statement, but I can't work > out how I would then specify the XXX'Tag attribute of a variable. > Here's an example that illustrates my problem ("if Var_A'Tag..." is the > problem line): > -- problem line: > if Var_A'Tag = Type_A'Tag then > Ada.Integer_Text_IO.Put ( Type_A (Var_A.all).Data); > elsif Var_A'Tag = Type_B'Tag then > Ada.Float_Text_IO.Put ( Type_B (Var_A.all).Data); > end if; > end Simple_Case; I offer you two alternatives. First one, would be: with Ada.Tags; procedure ... use type Ada.Tags.Tag; -- This makes operators on type Tag visible, without -- needing to use the whole package. begin if Var_A'Tag = Type_A'Tag then -- Should work now. And, the preferred method I guess, without "withing" Ada.Tags: if Var_A.all in Type_A then -- Is A instance of Type_A? if Var_A.all in Type_A'Class then -- Is Type_A or descendent? See this test program: ----8<-------- with Text_Io; use Text_Io; procedure Test_Tag is type X is tagged null record; type Y is new X with null record; type Z is new Y with null record; vz : Z; vn : constant X'Class := vz; begin Put_Line (Boolean'Image (vn in Y)); Put_Line (Boolean'Image (vn in Y'Class)); end Test_Tag; ----8<--------