From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Good/best way to enforce library-level instantiation a generic package
Date: Mon, 16 Mar 2020 20:21:16 -0500
Date: 2020-03-16T20:21:16-05:00 [thread overview]
Message-ID: <r4p8md$otc$1@franka.jacob-sparre.dk> (raw)
In-Reply-To: 6bcc6133-8c8b-4252-a8e6-fd64a5eec2ca@googlegroups.com
"Vincent Marciante" <vincent.marciante@l3harris.com> wrote in message
news:6bcc6133-8c8b-4252-a8e6-fd64a5eec2ca@googlegroups.com...
>I made a generic package that I want only to be instantiated at library
>level.
> I'm working on compile-time a way to enforce that desire which involves
> access
> type accessibility level checking but have not yet set it up correctly.
> Is there a better/standard way?
For Ada 95, deriving from Controlled does the trick, but that was eliminated
(at substantial cost) in Ada 2005 and later.
I suppose you could use type String_Access (which is a library-level access
type) for this:
with Ada.Strings.Unbounded;
generic
...
package My_Generic is
-- Real stuff here.
Library-Level : constant aliased String := "Library-Level";
Check : Ada.Strings.Unbounded.String_Access := Library_Level'Access;
-- 'Access is illegal if My_Generic is not instantiated at the
library level.
end My_Generic;
String_Access is a silly type that isn't used in the spec of
Ada.Strings.Unbounded, and thus shouldn't be there, but it does work for
this use. :-)
You can of course use any library-level access type in your program for this
purpose; I picked this one 'cause it is already sitting around.
Hope this helps.
Randy.
next prev parent reply other threads:[~2020-03-17 1:21 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-16 18:51 Good/best way to enforce library-level instantiation a generic package Vincent Marciante
2020-03-17 1:21 ` Randy Brukardt [this message]
2020-03-17 10:11 ` Vincent Marciante
2020-03-17 11:21 ` Jeffrey R. Carter
2020-03-18 1:03 ` Randy Brukardt
2020-03-18 9:23 ` Jeffrey R. Carter
2020-03-20 20:37 ` Randy Brukardt
2020-03-18 10:27 ` Vincent Marciante
2020-03-17 6:29 ` briot.emmanuel
2020-03-17 10:15 ` Vincent Marciante
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox