DocAda(tm) is a productivity tool of KSCE

Prev | Up | Next | Back | Forward
About DocAda Light: Preface / Preliminary / Help / TOC / Copyright
DocAda Online at the Ada Home: Complete RM95 / Updates / News

12.2 Generic Bodies

The body of a generic unit (a generic body) is a template for the instance bodies. The syntax of a generic body is identical to that of a nongeneric body.

Dynamic Semantics

The elaboration of a generic body has no other effect than to establish that the generic unit can from then on be instantiated without failing the Elaboration_Check. If the generic body is a child of a generic package, then its elaboration establishes that each corresponding declaration nested in an instance of the parent (see 10.1.1) can from then on be instantiated without failing the Elaboration_Check.

Examples

Example of a generic procedure body:

   
       procedure Exchange(U, V : in out Elem) is  -- see 12.1
          T : Elem;  --  the generic formal type
       begin
          T := U;
          U := V;
          V := T;
       end Exchange;

Example of a generic function body:

   
       function Squaring(X : Item) return Item is  --  see 12.1
       begin
          return X*X;  --  the formal operator "*"
       end Squaring;

Example of a generic package body:

   
       package body On_Vectors is  --  see 12.1

          function Sum(A, B : Vector) return Vector is
             Result : Vector(A'Range); --  the formal type Vector
             Bias   : constant Integer := B'First - A'First;
          begin
             if A'Length /= B'Length then
                raise Length_Error;
             end if;

             for N in A'Range loop
                Result(N) := Sum(A(N), B(N + Bias)); -- the formal function Sum
             end loop;
             return Result;
          end Sum;

          function Sigma(A : Vector) return Item is
             Total : Item := A(A'First); --  the formal type Item
          begin
             for N in A'First + 1 .. A'Last loop
                Total := Sum(Total, A(N)); --  the formal function Sum
             end loop;
             return Total;
          end Sigma;
       end On_Vectors;

About DocAda Light: Preface / Preliminary / Help / TOC / Copyright
DocAda Online at the Ada Home: Complete RM95 / Updates / News
Prev | Up | Next | Back | Forward


Copyright © 1994-1997 by Kempe Software Capital Enterprises. All Rights Reserved. For comments on this DocAda(tm) hypertext document, please write to KSCE, at docada@ksce.com