CVS difference for ais/ai-00390.txt

Differences between 1.1 and version 1.2
Log of other versions for file ais/ai-00390.txt

--- ais/ai-00390.txt	2004/11/14 04:54:48	1.1
+++ ais/ai-00390.txt	2004/11/17 00:52:59	1.2
@@ -1,4 +1,4 @@
-!standard 08.05.04    (02)                           04-11-13  AI95-00390/01
+!standard 08.05.04    (02)                           04-11-14  AI95-00390/02
 !standard 08.05.04    (03)
 !class amendment 04-11-13
 !status work item 04-11-13
@@ -60,7 +60,69 @@
 
 !example
 
-(** Missing **)
+   -- Here is an example where we define an integer set type
+   -- and then implement it using an instantiation of a set generic.
+   -- Many, but not all of the operations from the generic
+   -- are to be reexported for the private integer set type.
+
+     generic
+         with type Element is private;
+     package Sets is
+         -- A typical "set" generic
+         type Set is private;
+         function Union(Set1, Set2 : Set) return Set;
+         function Intersection(Set1, Set2 : Set) return Set;
+         ...
+     end Sets;
+
+     ...
+
+     type Int_Set is private;
+       -- A private integer "set" type.
+     function Union(L, R : Int_Set) return Int_Set;
+     function Intersection(L, R : Int_Set) return Int_Set;
+     ...
+   private
+     package Int_Sets is new Sets(Integer);
+     type Int_Set is new Int_Sets.Set;
+       -- Union and Intersection inherited from Int_Sets.Set,
+       -- and then immediately overridden by the explicitly declared
+       -- operations from the visible part
+
+     function Union(L, R : Int_Set) return Int_Set renames <>;
+     function Intersection(L, R : Int_Set) return Int_Set renames <>;
+       -- Define visible operations by renaming the ones they override
+
+--------
+
+   -- Here is an example where we provide a string reference
+   -- type, which makes it more convenient to deal with strings
+   -- by using a level of indirection.  The "=" turns out
+   -- to be able to use the predefined operation, although that
+   -- is only because we plan to store all the strings in a hash
+   -- table so that the string_ref is one-to-one with distinct
+   -- strings.
+
+     type String_Ref is private;
+     function To_Ref(S : String) return String_Ref;
+     function To_Str(R : String_Ref) return String;
+     function "="(R1, R2 : String_Ref) return Boolean;
+       -- Return True if R1 and R2 designate equal strings
+     function "&"(R1, R2 : String_Ref) return String_Ref;
+     ...
+   private
+     type String_Rec(Len: Natural) is record
+         Text : String(1..Len);
+         Next_Same_Hash : String_Ref;
+     end record;
+
+     type String_Ref is access String_Rec;
+       -- predefined "=" declared here and then immediately overridden
+       -- by explicitly declared one from visible part
+     function "="(R1, R2 : String_Ref) return Boolean renames <>;
+       -- define "=" in terms of predefined operator it overrode
+       -- because unique hashing will ensure the predefined
+       -- operator works correctly
 
 --!corrigendum
 

Questions? Ask the ACAA Technical Agent