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 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED.fn3LatRFkm9/xzEj7F2/NQ.user.gioia.aioe.org!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: How to access Vector.Index_Type? Date: Mon, 18 Mar 2019 09:31:52 +0100 Organization: Aioe.org NNTP Server Message-ID: References: NNTP-Posting-Host: fn3LatRFkm9/xzEj7F2/NQ.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.5.3 Content-Language: en-US X-Notice: Filtered by postfilter v. 0.9.2 Xref: reader01.eternal-september.org comp.lang.ada:55888 Date: 2019-03-18T09:31:52+01:00 List-Id: 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