From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: How to access Vector.Index_Type?
Date: Mon, 18 Mar 2019 09:31:52 +0100
Date: 2019-03-18T09:31:52+01:00 [thread overview]
Message-ID: <q6nl1o$fot$1@gioia.aioe.org> (raw)
In-Reply-To: q6na7f$bjj$1@dont-email.me
On 2019-03-18 06:27, J-P. Rosen wrote:
> Le 17/03/2019 à 21:43, jakub.dabek@gmail.com a écrit :
>> I have the following program
>>
>> with Ada.Containers.Vectors;
>>
>> procedure Test is
>> package MyVec is new Ada.Containers.Vectors(Natural, Natural);
>> Var : MyVec.Index_Type;
>> begin
>> null;
>> end;
>>
>> I get the following error:
>> "Index_Type" is not a visible entity of "MyVec"
>>
>> How can I access the index type (`Element_Type` gives the same error
>> message), without just writing `Natural`?
>>
> Why would you do that? If you instantiate Vectors on Natural, it's
> because you want a vector of Natural! Therefore it makes sense to use
> Natural. The name "Index_Type" is a formal, not an actual type, it's
> just the package's business.
surely for maintenance and code quality reasons. In the example
everything is clear, but in other (more realistic) scenarios the package
MyVec might come from other packages only to be used in Test. The
procedure Test must then use the least possible assumption about the
index type and be ready to the cases when the type would change, e.g.
become an enumeration type.
P.S. It is a longstanding issue with visibility of formal generic
parameters. Anybody who used generics was hit by it more than once. I
don't know if anything was attempted recently to fix that. A life-hack
(that does not apply to existing packages) was/is to rename or subtype
each formal parameter of the generic:
generic
type T is <>;
with package Bar ...
package Foo is
subtype The_T is T;
package The_Bar renames Bar;
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
next prev parent reply other threads:[~2019-03-18 8:31 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-17 20:43 How to access Vector.Index_Type? jakub.dabek
2019-03-17 21:25 ` Simon Wright
2019-03-18 0:12 ` jakub.dabek
2019-03-18 8:21 ` Simon Wright
2019-03-18 4:17 ` gautier_niouzes
2019-03-18 5:27 ` J-P. Rosen
2019-03-18 8:31 ` Dmitry A. Kazakov [this message]
2019-03-18 20:59 ` briot.emmanuel
2019-03-18 23:01 ` J-P. Rosen
2019-03-18 19:35 ` Jeffrey R. Carter
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox