comp.lang.ada
 help / color / mirror / Atom feed
From: NCOHEN@IBM.COM ("Norman H. Cohen")
Subject: Abstraction of variable size vectors (Corrected)
Date: 2 Aug 90 14:58:57 GMT	[thread overview]
Message-ID: <9008021525.AA10630@ajpo.sei.cmu.edu> (raw)

Ref: INFO-ADA Digest Volume 90 Issue 148 (Wed, Aug 1, 1990) Item #1

It took me a while to figure out what Louis-Simon Binette was trying to
do.  As I understand it, he is trying to imitate Ada arrays with his
own private type, specifying the index and components as generic
parameters.  He needs to store descriptor information--upper and lower
bounds of his imitation arrays--but these values may come from outside
the index subtype.  For example (by analogy to a null string), the
index subtype may be Positive, the lower bound may be one, AND THE UPPER
BOUND MAY BE ZERO.

The solution is simply to pass the index BASE type rather than the index
SUBtype as the generic actual parameter:

   generic
      type Element_Type is private;
      type Index_Base_Type is (<>);
      Index_Subtype_Lower_Bound, Index_Subtype_Upper_Bound:
         in Index_Base_Type;
   package Vector_Manager_Template is
      type Vector is limited private;
      ...
   private
      type Vector is
         record
            Vector_Lower_Bound, Vector_Upper_Bound: Index_Base_Type;
            ...
         end record;
   end Vector_Manager_Template;

The index subtype bounds are passed as generic parameters so that
when a Vector value is created with specified bounds, the package can
check whether the bounds are compatible with the index subtype.

Norman H. Cohen

             reply	other threads:[~1990-08-02 14:58 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1990-08-02 14:58 "Norman H. Cohen" [this message]
  -- strict thread matches above, loose matches on Subject: below --
1990-08-01 18:36 Abstraction of variable size vectors (Corrected) Louis-Simon Binette
replies disabled

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