comp.lang.ada
 help / color / mirror / Atom feed
From: Shark8 <onewingedshark@gmail.com>
Subject: Re: Array of Unbounded_String vs Indefinite_Vectors(Natural, String)
Date: Sat, 21 Oct 2017 17:51:26 -0700 (PDT)
Date: 2017-10-21T17:51:26-07:00	[thread overview]
Message-ID: <9588f435-6437-458d-9a3a-468fc96e0865@googlegroups.com> (raw)
In-Reply-To: <osgfbr$vfc$1@gioia.aioe.org>

On Saturday, October 21, 2017 at 3:48:48 PM UTC-6, Victor Porton wrote:
> I need to develop an API which return a list of strings.
> 
> I have two possible design choices for the result type:
> 
> 1. type T is array(Natural range <>) of Unbounded_String;
> 
> 2. package V is new Ada.Containers.Indefinite_Vectors(Natural, String);
> 
> Which one of the two to choose?
> 
> The first has the advantage that it is a regular array not a fancy 
> container. The second one has the advantage that the element type is String 
> not a fancy Unbounded_String.
> 
> Please help me to make the choice!

Personally I like the vector option.
There's a third choice, an array of unconstrained Holder container -- http://www.ada-auth.org/standards/12rat/html/Rat12-8-5.html -- You could overload your array-type with an operator to directly return the string.

Assuming you've instantiated String_Holder, you could do something like this.

Type String_List is Array(Positive range <>) of String_Holder.Holder;
Function "/"( List : String_List; Index : Positive ) return String is
( String_Holder.Element( List(Index) ) )
with Pre => Index in List'Range;


  reply	other threads:[~2017-10-22  0:51 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-21 21:48 Array of Unbounded_String vs Indefinite_Vectors(Natural, String) Victor Porton
2017-10-22  0:51 ` Shark8 [this message]
2017-10-22 10:52   ` Victor Porton
2017-10-23 16:32     ` Shark8
2017-10-23 17:30       ` Jacob Sparre Andersen
2017-11-06  4:42       ` Robert Eachus
2017-10-22 12:30 ` Victor Porton
replies disabled

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