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!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: "Jeffrey R. Carter" Newsgroups: comp.lang.ada Subject: Re: Bounded String question Date: Wed, 11 Nov 2015 10:27:37 -0700 Organization: Also freenews.netfront.net; news.tornevall.net; news.eternal-september.org Message-ID: References: <7ba56b33-28d4-42d2-8b9b-5ad9f5beab8b@googlegroups.com> <87io597447.fsf@theworld.com> <66278720-249a-4191-a908-bb840e7f3ccc@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Injection-Date: Wed, 11 Nov 2015 17:25:22 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="caa759af2a9c666aec02942f6fe5abd6"; logging-data="13671"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/gfMij41Xy0+hWWPpyKO2BmI5TcfAZqbw=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 In-Reply-To: Cancel-Lock: sha1:zuILf6RD7Y5bA9ZhPFVpa6t2UTc= X-Enigmail-Draft-Status: N1110 Xref: news.eternal-september.org comp.lang.ada:28304 Date: 2015-11-11T10:27:37-07:00 List-Id: On 11/11/2015 06:43 AM, Serge Robyns wrote: > On Wednesday, 11 November 2015 11:52:13 UTC+1, Serge Robyns wrote: >> I've had to write loads of functions like "To_Client_Name (Name : in >> String) >return T_Client_Name is (T_Client_Name >> (P_Strings.To_Bounded_String (Name));" Only if you want a name other than To_Bounded_String. > What does escape my understanding is why can I use To_String with any type > defined from P_Strings but have to define all the To_xyz explicitly. Is > there a kind of "hidden" conversion applied in that case? When you create a derived type, such as T_Client_Name, it inherits all the primitive operations of its parent. In this case, that includes To_String and To_Bounded_String. So you get functions function To_String (S : T_Client_Name) return String; function To_Bounded_String (S : String) return T_Client_Name; Basically, all the operations in Generic_Bounded_Length that have a parameter or return type of Bounded_String, with Bounded_String replaced by the name of the derived type. If you want something named To_T_Client_Name then of course you have to define it yourself: function To_T_Client_Name (S : String ) return T_Client_Name renames To_Bounded_String; The following compiles: with Ada.Strings.Bounded; procedure BS_Test is package BS is new Ada.Strings.Bounded.Generic_Bounded_Length (20); type OS is new BS.Bounded_String; B : OS := To_Bounded_String ("asdfghjkl"); S : String := To_String (B); begin -- BS_Test null; end BS_Test; -- Jeff Carter "When Roman engineers built a bridge, they had to stand under it while the first legion marched across. If programmers today worked under similar ground rules, they might well find themselves getting much more interested in Ada!" Robert Dewar 62