comp.lang.ada
 help / color / mirror / Atom feed
From: "Jeffrey R. Carter" <spam.jrcarter.not@spam.not.acm.org>
Subject: Re: Bounded String question
Date: Wed, 11 Nov 2015 13:42:55 -0700
Date: 2015-11-11T13:42:55-07:00	[thread overview]
Message-ID: <n20947$v1d$2@dont-email.me> (raw)
In-Reply-To: <d3958370-a3c5-4aac-9abf-bc9ddc873494@googlegroups.com>

On 11/11/2015 01:06 PM, Serge Robyns wrote:
> 
> I had to specify the full signature of To_Bounded_String, including default value to make it work with sub types.

Sorry, I forgot the Drop parameter.

>    package BS is new Ada.Strings.Bounded.Generic_Bounded_Length (20);
> 
>    type OS is new BS.Bounded_String;
>    
>    No_OS : OS renames BS.Null_Bounded_String;   
>    function To_OS (Source : in String;
>                   Drop : in Truncation := Error) return OS renames BS.To_Bounded_String;

These won't work. BS.Null_Bounded_String has type BS.Bounded_String, not OS.
However, you can convert BS.Null_Bounded_String

No_OS : constant OS := OS (BS.Null_Bounded_String);

or create your own

No_OS : constant OS := To_String ("");

Calling To_String requires elaboration.

Similarly, BS.To_Bounded_String returns BS.Bounded_String, not OS. However,
there is a directly visible To_Bounded_String that returns OS, and you can
rename that if you want:

function To_OS (Source : in String; Drop : in Truncation := Error)
return OS renames To_Bounded_String;

-- 
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


  parent reply	other threads:[~2015-11-11 20:42 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-10 22:00 Bounded String question Serge Robyns
2015-11-11  0:48 ` Bob Duff
2015-11-11  2:01   ` Jeffrey R. Carter
2015-11-11 15:34     ` Bob Duff
2015-11-11 17:36       ` Jeffrey R. Carter
2015-11-11 19:22         ` Bob Duff
2016-03-06 18:59       ` Xavier Petit
2016-03-07 23:16         ` Randy Brukardt
2016-03-08  0:08           ` Jeffrey R. Carter
2016-03-09  1:18             ` Randy Brukardt
2015-11-11 10:52   ` Serge Robyns
2015-11-11 13:43     ` Serge Robyns
2015-11-11 14:32       ` brbarkstrom
2015-11-11 16:08         ` Serge Robyns
2015-11-11 17:27       ` Jeffrey R. Carter
2015-11-11 20:06         ` Serge Robyns
2015-11-11 20:23           ` AdaMagica
2015-11-11 20:27             ` AdaMagica
2015-11-11 20:32             ` Serge Robyns
2015-11-11 20:40               ` AdaMagica
2015-11-12 17:31                 ` Serge Robyns
2015-11-12 19:10                   ` AdaMagica
2015-11-12 21:29                     ` Randy Brukardt
2015-11-12 18:03                 ` G.B.
2015-11-12 18:13                   ` Serge Robyns
2015-11-12 18:14                     ` Serge Robyns
2015-11-12 19:37                   ` Randy Brukardt
2015-11-11 20:42           ` Jeffrey R. Carter [this message]
2015-11-12 16:59             ` Serge Robyns
2015-11-12 18:39               ` Jeffrey R. Carter
2015-11-12 21:19                 ` Randy Brukardt
2015-11-12 21:27               ` Randy Brukardt
2015-11-12 22:32                 ` Jeffrey R. Carter
2015-11-13  0:07                   ` Randy Brukardt
2015-11-13  1:01                     ` Jeffrey R. Carter
2015-11-11 15:41     ` Bob Duff
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox