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.3d73Ybk3C5U4I2t8lv+lAQ.user.gioia.aioe.org!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Using Generic Pasckages Date: Thu, 9 Apr 2020 13:23:51 +0200 Organization: Aioe.org NNTP Server Message-ID: References: <5e8edf69$0$18432$e4fe514c@news.kpn.nl> NNTP-Posting-Host: 3d73Ybk3C5U4I2t8lv+lAQ.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:68.0) Gecko/20100101 Thunderbird/68.6.0 Content-Language: en-US X-Notice: Filtered by postfilter v. 0.9.2 Xref: reader01.eternal-september.org comp.lang.ada:58335 Date: 2020-04-09T13:23:51+02:00 List-Id: On 2020-04-09 12:05, ldries46 wrote: > Op 9-4-2020 om 10:57 schreef Dmitry A. Kazakov: >> On 2020-04-09 10:40, ldries46 wrote: >>> I have created some generic packages. tese are packages that only do >>> the same thing but with other types. Till now I did only need these >>> packages without interaction with between packages using the same >>> type. I just can declare them: >>> Package AA is new BB(type); then calling them as >>> A := AA.Get_Value; >>> No other declaration seemed to be neccesary . >>> >>> Now I have the following situation: >>> Package AA is new BB(integer); >>> Package CC is new BB(integer); >>> and a case where I have several statements using Package AA in one >>> condition and CC the other case. >>> I want  to do that by using: >>> if D then EE := AA; else EE := CC; end if; >>> But I cannot find in the documentation  how the declaration of EE >>> should be made. >>> >>> Of course there is the possibility to create the same progrram >>> without using EE but that is far less readable and thus creating more >>> possible errors. >>> >>> If I have to do this without the generic packages I already have the >>> program alse will be less readable. >> >> What you are observing is the advantages of dynamic polymorphism >> (tagged types) over the static one (generics). >> >> Already the name static hints that you cannot select a polymorphic >> implementation (AA or CC) using some non-static (dynamic) expression D. >> > I am using Generic because in the program the same routines should be > possible for several different types, but now I have also a situation > where two instantiations of the same type should be used under some > conditions. For instance in a instantiation of a buffer of > Unbounded.String's depending on the condition one of two should be used, > but the buffer should also be used for another type A solution, without going into what to change in Ada, is to make an interface and put data, e.g. Unbounded_String into an implementation of. BB will work on the interface's class. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de