comp.lang.ada
 help / color / mirror / Atom feed
From: eachus@spectre.mitre.org (Robert I. Eachus)
Subject: Re: overload ":=" ???
Date: 1996/07/24
Date: 1996-07-24T00:00:00+00:00	[thread overview]
Message-ID: <EACHUS.96Jul24153824@spectre.mitre.org> (raw)
In-Reply-To: 4soh73$56h@newsbf02.news.aol.com


In article <TARJEIJ.96Jul23153224@ulrik.uio.no> tarjeij@ulrik.uio.no (Tarjei Jensen) writes:

  > The problem with bounded string is that it assigns a global
  > maximum string size instead of letting each string have its own
  > maximum size. The former is not particularly flexible while the
  > latter really require a user defined ":=".

   The generic package Ada.Strings.Bounded can be instantiated as
often as you want.  I have written program which had six
instantiations...  Well, not really.  It had five instantiations which
occured once per program invocation, and a sixth whose size was
determined every time the enclosing procedure was called.

  > Not the least because the maximum length of the strings might be different.

  > e.g:

  >   a : counted_string(4) := "1234";
  >   b : counted_string(5) := "1234";  -- four characters and space for five

  >   a := b;  -- Will not work with current version of Ada

   Try:

   ...
   package Counted is new Ada.Strings.Bounded.Generic_Bounded_Length(10);
   A : Counted.Bounded_String := To_Bounded_String("1234");
   B : Counted.Bounded_String := To_Bounded_String("Some value");
   ...
   A := B; --works fine.
   
   Of couse if instead you say:
   ...
   package Counted4 is new Ada.Strings.Bounded.Generic_Bounded_Length(4);
   package Counted5 is new Ada.Strings.Bounded.Generic_Bounded_Length(5);
   A : Counted4.Bounded_String := To_Bounded_String("1234");
   B : Counted5.Bounded_String := To_Bounded_String("1234");

   Now you have to write:
   ...
   A := Counted4.To_Bounded_String(Counted5.To_String(B));
   
   Of course, if you want, you can make all this less verbose by using
use clauses and perhaps even defining a conversion operation:

   function Convert(B: in Counted5.Bounded_String) 
           return Counted4.Bounded_String is
   begin return Counted4.To_Bounded_String(Counted5.To_String(B)); end;
   pragma Inline(Convert);

--

					Robert I. Eachus

with Standard_Disclaimer;
use  Standard_Disclaimer;
function Message (Text: in Clever_Ideas) return Better_Ideas is...




  parent reply	other threads:[~1996-07-24  0:00 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-07-17  0:00 overload ":=" ??? David Morton
1996-07-17  0:00 ` Robert Dewar
1996-07-18  0:00   ` Laurent Guerby
1996-07-18  0:00   ` David Morton
1996-07-19  0:00     ` Brad Balfour
1996-07-19  0:00     ` David Weller
1996-07-25  0:00   ` Wolfgang Gellerich
1996-07-25  0:00     ` Robert A Duff
1996-07-18  0:00 ` John Herro
1996-07-18  0:00   ` Robert Dewar
1996-07-19  0:00     ` John Herro
1996-07-21  0:00       ` David Morton
1996-07-21  0:00       ` Laurent Guerby
1996-07-22  0:00         ` Robert A Duff
1996-07-23  0:00           ` Laurent Guerby
1996-07-23  0:00             ` John Herro
1996-07-23  0:00             ` Robert A Duff
1996-07-22  0:00       ` David Morton
1996-07-22  0:00         ` Robert Dewar
1996-07-23  0:00         ` Robert A Duff
1996-07-22  0:00           ` Robert Dewar
1996-07-22  0:00       ` Laurent Guerby
1996-07-22  0:00       ` Laurent Guerby
1996-07-23  0:00       ` Tarjei Jensen
1996-07-23  0:00         ` Robert A Duff
1996-07-24  0:00       ` Robert I. Eachus [this message]
1996-07-18  0:00 ` Jon S Anthony
1996-07-19  0:00 ` Joerg Ozimek
replies disabled

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